From 0e98301dc1f2ecd0c533d9c8dd691aedc7c093e4 Mon Sep 17 00:00:00 2001 From: Dmitry Vodich Date: Fri, 25 Oct 2019 13:21:50 +0300 Subject: [PATCH] Fixed issue #83 with LayoutDocument disappearance. --- .../Layout/LayoutContent.cs | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/source/Components/Xceed.Wpf.AvalonDock/Layout/LayoutContent.cs b/source/Components/Xceed.Wpf.AvalonDock/Layout/LayoutContent.cs index 848fca18..a7fa47af 100644 --- a/source/Components/Xceed.Wpf.AvalonDock/Layout/LayoutContent.cs +++ b/source/Components/Xceed.Wpf.AvalonDock/Layout/LayoutContent.cs @@ -93,11 +93,7 @@ public object Content if( this.ContentId == null ) { - var contentAsControl = _content as FrameworkElement; - if( contentAsControl != null && !string.IsNullOrWhiteSpace( contentAsControl.Name ) ) - { - this.SetCurrentValue( LayoutContent.ContentIdProperty, contentAsControl.Name ); - } + SetContentIdFromContent(); } } } @@ -112,7 +108,13 @@ public string ContentId { get { - return (string)GetValue( ContentIdProperty ); + string value = (string)GetValue(ContentIdProperty); + if (!string.IsNullOrWhiteSpace(value)) return value; + + // #83 - if Content.Name is empty at setting content and will be set later, ContentId will stay null. + SetContentIdFromContent(); + + return (string)GetValue(ContentIdProperty); } set { @@ -136,6 +138,16 @@ private void OnContentIdPropertyChanged( string oldValue, string newValue ) this.RaisePropertyChanged( "ContentId" ); } } + + private void SetContentIdFromContent() + { + var contentAsControl = _content as FrameworkElement; + if (!string.IsNullOrWhiteSpace(contentAsControl?.Name)) + { + this.SetCurrentValue(LayoutContent.ContentIdProperty, contentAsControl.Name); + } + } + #endregion ContentId #region IsSelected