Skip to content

Commit

Permalink
Fixing memory leak via IsVisibleChanged event and SingleContentLayout…
Browse files Browse the repository at this point in the history
…Item and Visibility property binding on LayoutAnchorableFloatingWindowControl
  • Loading branch information
Dirkster99 committed Oct 5, 2019
1 parent aed7a02 commit deab478
Showing 1 changed file with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,7 @@ protected override void OnInitialized( EventArgs e )
//SetBinding(VisibilityProperty, new Binding("IsVisible") { Source = _model, Converter = new BoolToVisibilityConverter(), Mode = BindingMode.OneWay, ConverterParameter = Visibility.Hidden });

//Issue: http://avalondock.codeplex.com/workitem/15036
IsVisibleChanged += ( s, args ) =>
{
var visibilityBinding = GetBindingExpression( VisibilityProperty );
if( visibilityBinding == null && IsVisible )
{
SetVisibilityBinding();
}
};
IsVisibleChanged += this.LayoutAnchorableFloatingWindowControl_IsVisibleChanged;

SetBinding( SingleContentLayoutItemProperty, new Binding( "Model.SinglePane.SelectedContent" ) { Source = this, Converter = new LayoutItemFromLayoutModelConverter() } );

Expand Down Expand Up @@ -201,8 +194,10 @@ protected override void OnClosed( EventArgs e )
BindingOperations.ClearBinding(_model, VisibilityProperty);

_model.PropertyChanged -= new System.ComponentModel.PropertyChangedEventHandler( _model_PropertyChanged );

Activated -= LayoutAnchorableFloatingWindowControl_Activated;
IsVisibleChanged -= this.LayoutAnchorableFloatingWindowControl_IsVisibleChanged;
BindingOperations.ClearBinding( this, VisibilityProperty );
BindingOperations.ClearBinding( this, SingleContentLayoutItemProperty );
}

protected override void OnClosing( System.ComponentModel.CancelEventArgs e )
Expand Down Expand Up @@ -380,7 +375,18 @@ public override void DisableBindings()
base.DisableBindings();
}

#endregion
#endregion

#region Event Handlers
private void LayoutAnchorableFloatingWindowControl_IsVisibleChanged( object sender, DependencyPropertyChangedEventArgs e )
{
var visibilityBinding = GetBindingExpression( VisibilityProperty );
if( IsVisible && ( visibilityBinding == null ) )
{
SetBinding( VisibilityProperty, new Binding( "IsVisible" ) { Source = _model, Converter = new BoolToVisibilityConverter(), Mode = BindingMode.OneWay, ConverterParameter = Visibility.Hidden } );
}
}
#endregion Event Handlers

#region Commands

Expand Down

0 comments on commit deab478

Please sign in to comment.