Skip to content

Commit

Permalink
prevent leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward Miller committed Mar 25, 2024
1 parent 69d2002 commit b4c8750
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions Maui.DataGrid/DataGrid.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ public DataGrid()
{
_collectionView.ItemsSource = InternalItems;
}

Loaded += (sender, e) =>
{
Initialize();
};
}

#endregion ctor
Expand Down Expand Up @@ -1226,6 +1221,16 @@ protected override void OnParentSet()
{
base.OnParentSet();

if (Parent is null)
{
Loaded -= OnLoaded;
}
else
{
Loaded -= OnLoaded;
Loaded += OnLoaded;
}

if (Parent is null)
{
_collectionView.SelectionChanged -= OnSelectionChanged;
Expand Down Expand Up @@ -1268,6 +1273,8 @@ protected override void OnParentSet()
}
}

private void OnLoaded(object? sender, EventArgs e) => Initialize();

/// <inheritdoc/>
protected override void OnBindingContextChanged()
{
Expand Down

0 comments on commit b4c8750

Please sign in to comment.