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

After changing the style (theme), when you pin a side bar it will disappear #402

Closed
mladdaga opened this issue Dec 1, 2022 · 2 comments · Fixed by #414
Closed

After changing the style (theme), when you pin a side bar it will disappear #402

mladdaga opened this issue Dec 1, 2022 · 2 comments · Fixed by #414

Comments

@mladdaga
Copy link

mladdaga commented Dec 1, 2022

After hours of research I found that in LayoutAnchorSideControl, in the LayoutAnchorSideControl_Unloaded method, for some reason, it's removed the collectionChanged handler on the model's children
_model.Children.CollectionChanged -= OnModelChildrenCollectionChanged;
Removing this line from the code everything works fine.
It seems that is the root of a lot of other Issues opened around the load of a different theme.

It's easy to reproduce on the MVVMTestApp

image

image

image

image

@Wenveo
Copy link
Contributor

Wenveo commented Dec 26, 2022

Hi mladdaga. Like you said, change the style (theme) and pin a side bar it will disappear.
This is due to the parent's template change, And the child control is disconnected (The Unloaded event handler will be raised).

ApplyNewTemplate (Change the template) -> Unloaded (The event handlers will be removed) -> Loaded (Reconnect, but we don't have the Loaded event handler)

private void LayoutAnchorSideControl_Unloaded(object sender, RoutedEventArgs e)
{
_model.Children.CollectionChanged -= OnModelChildrenCollectionChanged;
Unloaded -= LayoutAnchorSideControl_Unloaded;
}

@Wenveo
Copy link
Contributor

Wenveo commented Dec 26, 2022

Fortunately, we can add a Loaded event handler in OnApplyTemplate. So that we can add back the OnModelChildrenCollectionChanged event handler on apply the new template.

// LayoutAnchorSideControl.cs

public override void OnApplyTemplate()
{
	base.OnApplyTemplate();

	Loaded += LayoutAnchorSideControl_Loaded;
}

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;
	Unloaded -= LayoutAnchorSideControl_Unloaded;
}

image image

It will work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants