From d65e9a9019867b1019810329727c154cc20b4c90 Mon Sep 17 00:00:00 2001 From: Dirkster99 Date: Thu, 14 Feb 2019 19:45:52 +0100 Subject: [PATCH] LayoutRoot doesn't notify change for Children or ChildrenCount #1313 https://github.com/xceedsoftware/wpftoolkit/issues/1313 --- .../Xceed.Wpf.AvalonDock/Layout/LayoutRoot.cs | 79 ++++++++++++++++--- 1 file changed, 66 insertions(+), 13 deletions(-) diff --git a/source/Components/Xceed.Wpf.AvalonDock/Layout/LayoutRoot.cs b/source/Components/Xceed.Wpf.AvalonDock/Layout/LayoutRoot.cs index 78b39e25..e5da640a 100644 --- a/source/Components/Xceed.Wpf.AvalonDock/Layout/LayoutRoot.cs +++ b/source/Components/Xceed.Wpf.AvalonDock/Layout/LayoutRoot.cs @@ -771,32 +771,63 @@ internal void OnLayoutElementRemoved( LayoutElement element ) ElementRemoved( this, new LayoutElementEventArgs( element ) ); } - #endregion + #endregion #region Private Methods - private void _floatingWindows_CollectionChanged( object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e ) + private void _floatingWindows_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { - if( e.OldItems != null && ( e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove || - e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Replace ) ) + bool bNotifyChildren = false; + + if (e.OldItems != null && (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove || + e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Replace)) { - foreach( LayoutFloatingWindow element in e.OldItems ) + foreach (LayoutFloatingWindow element in e.OldItems) { - if( element.Parent == this ) + if (element.Parent == this) + { element.Parent = null; + bNotifyChildren = true; + } } } - if( e.NewItems != null && ( e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add || - e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Replace ) ) + if (e.NewItems != null && (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add || + e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Replace)) { - foreach( LayoutFloatingWindow element in e.NewItems ) + foreach (LayoutFloatingWindow element in e.NewItems) + { element.Parent = this; + bNotifyChildren = true; + } } - } + // descendants of LayoutElement notify when their Children and ChildrenCount properties change + // https://github.com/xceedsoftware/wpftoolkit/issues/1313 + // + if (bNotifyChildren == true && + (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove || + e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add + )) + { + RaisePropertyChanged("Children"); + RaisePropertyChanged("ChildrenCount"); + } + else + { + if (bNotifyChildren == true && + e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Replace) + { + RaisePropertyChanged("Children"); + } + } + } + + private void _hiddenAnchorables_CollectionChanged( object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e ) { + bool bNotifyChildren = false; + if( e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove || e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Replace ) { @@ -804,8 +835,11 @@ private void _hiddenAnchorables_CollectionChanged( object sender, System.Collect { foreach( LayoutAnchorable element in e.OldItems ) { - if( element.Parent == this ) + if( element.Parent == this) + { element.Parent = null; + bNotifyChildren = true; + } } } } @@ -821,15 +855,34 @@ private void _hiddenAnchorables_CollectionChanged( object sender, System.Collect { if( element.Parent != null ) element.Parent.RemoveChild( element ); + element.Parent = this; + bNotifyChildren = true; } } } } - - + // descendants of LayoutElement notify when their Children and ChildrenCount properties change + // https://github.com/xceedsoftware/wpftoolkit/issues/1313 + // + if (bNotifyChildren == true && + (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove || + e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add + )) + { + RaisePropertyChanged("Children"); + RaisePropertyChanged("ChildrenCount"); + } + else + { + if (bNotifyChildren == true && + e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Replace ) + { + RaisePropertyChanged("Children"); + } + } } private void InternalSetActiveContent( LayoutContent currentValue, LayoutContent newActiveContent )