Skip to content

Commit

Permalink
Log how many CheckBox alive
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpeppers committed Aug 17, 2023
1 parent cc55f63 commit 43af9ec
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
13 changes: 2 additions & 11 deletions MauiApp1/MauiApp1/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,8 @@
<Button Text="ItemSource 1" Clicked="ItemSource_One_Button_Clicked"/>
<Button Text="ItemSource 2" Clicked="ItemSource_Two_Button_Clicked"/>
</HorizontalStackLayout>
<ListView Grid.Row="1" x:Name="listView" ItemsSource="{Binding EmployeesInfo1}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<CheckBox x:Name="checkBoxCell" Margin="10,0,0,0" IsChecked="{Binding IsChecked}"
VerticalOptions="Center">
</CheckBox>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<ListView Grid.Row="1" x:Name="listView" ItemsSource="{Binding EmployeesInfo1}">
</ListView>
</Grid>

</ContentPage>
19 changes: 18 additions & 1 deletion MauiApp1/MauiApp1/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,45 @@

using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;

namespace MauiApp1
{
public partial class MainPage : ContentPage
{
List<WeakReference> references = new List<WeakReference>();


public MainPage()
{
InitializeComponent();

listView.ItemTemplate = new DataTemplate(() =>
{
var cell = new ViewCell { View = new Label() };
references.Add(new(cell.View));
return cell;
});
}

void Log()
{
Debug.WriteLine($"CheckBox's alive: {references.Count(l => l.IsAlive)}");
}

private void ItemSource_One_Button_Clicked(object sender, EventArgs e)
{
GC.Collect();
Log();
listView.ItemsSource = employeeInfoRepository.EmployeesInfo1;

}

private void ItemSource_Two_Button_Clicked(object sender, EventArgs e)
{
listView.ItemsSource = employeeInfoRepository.EmployeesInfo2;
GC.Collect();
Log();
listView.ItemsSource = employeeInfoRepository.EmployeesInfo2;
}
}
}

0 comments on commit 43af9ec

Please sign in to comment.