Skip to content

Commit

Permalink
When apply new template, add back collection change event handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Wenveo committed Dec 26, 2022
1 parent 1d4d30d commit 5f42e5c
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions source/Components/AvalonDock/Controls/LayoutAnchorSideControl.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/************************************************************************
/************************************************************************
AvalonDock
Copyright (C) 2007-2013 Xceed Software Inc.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -137,11 +132,27 @@ internal LayoutAnchorSideControl(LayoutAnchorSide model)

#region Private Methods

/// <summary>
/// Executes when the element is removed from within an element tree of loaded elements.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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;
Expand Down

0 comments on commit 5f42e5c

Please sign in to comment.