mirror of
https://github.com/microsoft/microsoft-ui-xaml.git
synced 2026-10-28 16:35:19 +08:00
NavigationView: re-prepare NavigationViewItems on every load and re-resolve the NavigationView for items moved between NavigationViews
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec9a38b2-2629-4a10-bfb5-552decfe6848
This commit is contained in:
1 parent
bb2a413b34
commit
5e358f0d4a
2 files changed
+13
-8
No files matched your search
@@ -173,18 +173,14 @@ void NavigationViewItem::LoadMenuItemsHost()
|
||||
|
||||
void NavigationViewItem::OnLoaded(winrt::IInspectable const&, winrt::RoutedEventArgs const&)
|
||||
{
|
||||
// Items in a NavigationView-owned repeater are prepared in OnApplyTemplate and refreshed by the repeater.
|
||||
if (IsInNavigationViewOwnedRepeater() && m_splitViewIsPaneOpenChangedRevoker)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// If the NVI is not prepared in an ItemPresenter, it will not have reference to SplitView, so it is prepared here once
|
||||
// NavigationViewItemBase::OnLoaded() has set the NavigationView. This also runs again when the item is loaded in a new host,
|
||||
// so the closed compact state is recomputed for that host. Re-preparing replaces the SplitView subscriptions.
|
||||
// NavigationViewItemBase::OnLoaded() has set the NavigationView. This also runs again when the item is loaded in a new host
|
||||
// (for example moved between MenuItems, PaneFooter, Content or another NavigationView), so the SplitView subscriptions and
|
||||
// the closed compact state follow the new host. Re-preparing replaces the previous SplitView subscriptions.
|
||||
if (auto splitView = GetSplitView())
|
||||
{
|
||||
PrepNavigationViewItem(splitView);
|
||||
ReparentRepeater();
|
||||
}
|
||||
|
||||
UpdateVisualStateForChevron();
|
||||
|
||||
@@ -24,6 +24,15 @@ void NavigationViewItemBase::OnLoaded(winrt::IInspectable const&, winrt::RoutedE
|
||||
{
|
||||
SetNavigationViewParent(SharedHelpers::GetAncestorOfType<winrt::NavigationView>(*this));
|
||||
}
|
||||
else if (!IsInNavigationViewOwnedRepeater())
|
||||
{
|
||||
// The item may have been moved to a different NavigationView. Keep the current reference if no ancestor is found
|
||||
// (for example when the item is hosted in a popup).
|
||||
if (auto const navigationView = SharedHelpers::GetAncestorOfType<winrt::NavigationView>(*this))
|
||||
{
|
||||
SetNavigationViewParent(navigationView);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NavigationViewRepeaterPosition NavigationViewItemBase::Position() const
|
||||
|
||||
Reference in new issue
Block a user