From 5f42e5cc0ba0a11cae1b3503d18e7f12c4d69a0f Mon Sep 17 00:00:00 2001 From: Noisrev Date: Tue, 27 Dec 2022 00:04:25 +0800 Subject: [PATCH] When apply new template, add back collection change event handler --- .../Controls/LayoutAnchorSideControl.cs | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/source/Components/AvalonDock/Controls/LayoutAnchorSideControl.cs b/source/Components/AvalonDock/Controls/LayoutAnchorSideControl.cs index c955ba79..e0453eed 100644 --- a/source/Components/AvalonDock/Controls/LayoutAnchorSideControl.cs +++ b/source/Components/AvalonDock/Controls/LayoutAnchorSideControl.cs @@ -1,4 +1,4 @@ -/************************************************************************ +/************************************************************************ AvalonDock Copyright (C) 2007-2013 Xceed Software Inc. @@ -46,11 +46,6 @@ static LayoutAnchorSideControl() internal LayoutAnchorSideControl(LayoutAnchorSide model) { _model = model ?? throw new ArgumentNullException(nameof(model)); - CreateChildrenViews(); - _model.Children.CollectionChanged += OnModelChildrenCollectionChanged; - UpdateSide(); - - Unloaded += LayoutAnchorSideControl_Unloaded; } #endregion Constructors @@ -137,11 +132,27 @@ internal LayoutAnchorSideControl(LayoutAnchorSide model) #region Private Methods - /// - /// Executes when the element is removed from within an element tree of loaded elements. - /// - /// - /// + public override void OnApplyTemplate() + { + base.OnApplyTemplate(); + + Loaded += LayoutAnchorSideControl_Loaded; + } + + protected override void OnInitialized(EventArgs e) + { + base.OnInitialized(e); + CreateChildrenViews(); + UpdateSide(); + } + + private void LayoutAnchorSideControl_Loaded(object sender, RoutedEventArgs e) + { + Loaded -= LayoutAnchorSideControl_Loaded; + Unloaded += LayoutAnchorSideControl_Unloaded; + _model.Children.CollectionChanged += OnModelChildrenCollectionChanged; + } + private void LayoutAnchorSideControl_Unloaded(object sender, RoutedEventArgs e) { _model.Children.CollectionChanged -= OnModelChildrenCollectionChanged;