Skip to content

Commit

Permalink
Fix for event handlers not being removed properly when the layout dis…
Browse files Browse the repository at this point in the history
…poses
  • Loading branch information
LaughingLeader committed Dec 21, 2019
1 parent 8e2cea4 commit 2d9da52
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions DivinityModManagerGUI_WPF/Views/HorizontalModLayout.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,32 @@ public MainWindowViewModel ViewModel

object IViewFor.ViewModel { get; set; }

private MainWindowViewModel _lastVM;

public HorizontalModLayout()
{
InitializeComponent();

this.WhenActivated((d) =>
{
ViewModel.OnOrderChanged += AutoSizeNameColumn_ActiveMods;
ViewModel.OnOrderChanged += AutoSizeNameColumn_InactiveMods;
_lastVM = ViewModel;

if(ViewModel != null)
{
ViewModel.OnOrderChanged += AutoSizeNameColumn_ActiveMods;
ViewModel.OnOrderChanged += AutoSizeNameColumn_InactiveMods;
}

// when the view model gets deactivated
Disposable.Create(() =>
{
ViewModel.OnOrderChanged -= AutoSizeNameColumn_ActiveMods;
ViewModel.OnOrderChanged -= AutoSizeNameColumn_InactiveMods;
if(_lastVM != null)
{
_lastVM.OnOrderChanged -= AutoSizeNameColumn_ActiveMods;
_lastVM.OnOrderChanged -= AutoSizeNameColumn_InactiveMods;

_lastVM = null;
}
}).DisposeWith(d);
});
}
Expand Down

0 comments on commit 2d9da52

Please sign in to comment.