From 6750692af7d6f701e7a189f2ed790c53a67c2693 Mon Sep 17 00:00:00 2001 From: dif-sam <41672086+dif-sam@users.noreply.github.com> Date: Wed, 23 Nov 2022 22:29:58 +0400 Subject: [PATCH] Fix SelectionChanged event unsubscribtions That change fix very tricky bug. Our case: We have DataTemplate that contains DataGrid inside it. And Datagrid has an AttachedProperty (that deserve us to observe changes in Datagrid's SelectedItems). which work through event subscription. Memory leaks happen (and the logic for observe selected items breaks) when DataTemplate switches DataContext. --- src/Avalonia.Controls.DataGrid/DataGrid.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Controls.DataGrid/DataGrid.cs b/src/Avalonia.Controls.DataGrid/DataGrid.cs index a9f2e889b9..5b6fbfe09f 100644 --- a/src/Avalonia.Controls.DataGrid/DataGrid.cs +++ b/src/Avalonia.Controls.DataGrid/DataGrid.cs @@ -1296,7 +1296,7 @@ namespace Avalonia.Controls public event EventHandler SelectionChanged { add { AddHandler(SelectionChangedEvent, value); } - remove { AddHandler(SelectionChangedEvent, value); } + remove { RemoveHandler(SelectionChangedEvent, value); } } ///