From c06efac6479a3bad1417356e39f5974dadedc662 Mon Sep 17 00:00:00 2001 From: Dirkster99 Date: Sun, 6 Oct 2019 20:34:47 +0200 Subject: [PATCH] Fixing NullReferenceException on LayoutElement in LayoutItem --- .../Xceed.Wpf.AvalonDock/Controls/LayoutItem.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/source/Components/Xceed.Wpf.AvalonDock/Controls/LayoutItem.cs b/source/Components/Xceed.Wpf.AvalonDock/Controls/LayoutItem.cs index 8e83d835..ab2f7b7e 100644 --- a/source/Components/Xceed.Wpf.AvalonDock/Controls/LayoutItem.cs +++ b/source/Components/Xceed.Wpf.AvalonDock/Controls/LayoutItem.cs @@ -94,9 +94,15 @@ public ContentPresenter View _view = new ContentPresenter(); _view.SetBinding( ContentPresenter.ContentProperty, new Binding( "Content" ) { Source = LayoutElement } ); - _view.SetBinding( ContentPresenter.ContentTemplateProperty, new Binding( "LayoutItemTemplate" ) { Source = LayoutElement.Root.Manager } ); - _view.SetBinding( ContentPresenter.ContentTemplateSelectorProperty, new Binding( "LayoutItemTemplateSelector" ) { Source = LayoutElement.Root.Manager } ); - LayoutElement.Root.Manager.InternalAddLogicalChild( _view ); + if( ( LayoutElement != null ) && ( LayoutElement.Root != null ) ) + { + _view.SetBinding( ContentPresenter.ContentTemplateProperty, new Binding( "LayoutItemTemplate" ) { Source = LayoutElement.Root.Manager } ); + _view.SetBinding( ContentPresenter.ContentTemplateSelectorProperty, new Binding( "LayoutItemTemplateSelector" ) { Source = LayoutElement.Root.Manager } ); + if( LayoutElement.Root.Manager != null ) + { + LayoutElement.Root.Manager.InternalAddLogicalChild( _view ); + } + } } return _view;