Skip to content

Commit

Permalink
Merge pull request #414 from Noisrev/fix-issue402
Browse files Browse the repository at this point in the history
When apply new template, add back collection change event handler
  • Loading branch information
Dirkster99 committed Dec 26, 2022
2 parents 24479e4 + 5f42e5c commit ba90c40
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 ba90c40

Please sign in to comment.