Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When apply new template, add back collection change event handler #414

Merged
merged 1 commit into from
Dec 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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