Skip to content

Commit

Permalink
fix: Leak caused by ButtonBase.Command
Browse files Browse the repository at this point in the history
Setting a Command on ButtonBase makes the control create a strong subscription to the CanExecuteChanged event of the command. This must be unsubscribed when the control is unloaded.
  • Loading branch information
MartinZikmund committed Jan 20, 2022
1 parent ac5daf5 commit bf6b6e1
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ private protected virtual void Initialize()
SetAcceptsReturn(true);

Loaded += OnLoaded;
//TODO Uno specific: Call LeaveImpl to simulate leaving visual tree
Unloaded += (s, e) => LeaveImpl();
}

internal override void OnPropertyChanged2(DependencyPropertyChangedEventArgs args)
{
//ButtonBaseGenerated.OnPropertyChanged2(args);
base.OnPropertyChanged2(args);

if (args.Property == ClickModeProperty)
{
Expand Down Expand Up @@ -299,7 +301,12 @@ private void ExecuteCommand()
/// </summary>
/// <param name="sender">Sender.</param>
/// <param name="args">Event args.</param>
private void OnLoaded(object sender, RoutedEventArgs args) => UpdateVisualState(false);
private void OnLoaded(object sender, RoutedEventArgs args)
{
UpdateVisualState(false);
// TODO Uno specific: Call EnterImpl to simulate entering visual tree
EnterImpl();
}

/// <summary>
/// GotFocus event handler.
Expand Down

0 comments on commit bf6b6e1

Please sign in to comment.