-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
the code fails to find the tag if the NavigationItem is a MenuItems child object, so I had to modify and add a function to recursively search for it.
Sorry I can't push the change, because I'm not sure of myself on github...
MainWindow.xaml.cs
`
private NavigationViewItem FindNavigationViewItemByTag(IEnumerable<object> menuItems, string tag)
{
foreach (var item in menuItems)
{
if (item is NavigationViewItem navigationViewItem)
{
if (navigationViewItem.Tag?.ToString() == tag)
{
return navigationViewItem;
}
var foundItem = FindNavigationViewItemByTag(navigationViewItem.MenuItems, tag);
if (foundItem != null)
{
return foundItem;
}
}
}
return null;
}
private void ContentFrame_Navigated(object sender, NavigationEventArgs e)
{
NavigationViewControl.IsBackEnabled = ContentFrame.CanGoBack;
if (ContentFrame.SourcePageType == typeof(Views.SettingsPage))
{
// SettingsItem is not part of NavView.MenuItems, and doesn't have a Tag.
NavigationViewControl.SelectedItem = (NavigationViewItem)NavigationViewControl.SettingsItem;
}
else if (ContentFrame.SourcePageType != null)
{
// NavigationViewControl.SelectedItem = NavigationViewControl.MenuItems
// .OfType<NavigationViewItem>()
// .First(n => n.Tag.Equals(ContentFrame.SourcePageType.FullName.ToString()));
var selectedItem = FindNavigationViewItemByTag(NavigationViewControl.MenuItems, ContentFrame.SourcePageType.FullName.ToString());
NavigationViewControl.SelectedItem = selectedItem;
}
NavigationViewControl.Header = ((NavigationViewItem)NavigationViewControl.SelectedItem)?.Content?.ToString();
}
`
Metadata
Metadata
Assignees
Labels
No labels