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

NavigationView: Throw exception when a WUX NavigationViewItem is added to it as a menu item #3232

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
8 changes: 8 additions & 0 deletions dev/NavigationView/NavigationViewItemsFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ winrt::UIElement NavigationViewItemsFactory::GetElementCore(winrt::ElementFactor
return newItem;
}

// Accidentally adding a OS XAML NavigationViewItem to WinUI's NavigationView can cause unnecessary confusion for developers
// due to unexpected rendering, potentially without an easy way to understand what went wrong here. To help out developers,
// we are explicitly checking for this scenario here and throw a helpful error message so that they can quickly fix their app.
if (newContent.try_as<winrt::Windows::UI::Xaml::Controls::NavigationViewItemBase>())
{
throw winrt::hresult_invalid_argument(L"A NavigationView instance contains a Windows.UI.Xaml.Controls.NavigationViewItem. This control requires that its NavigationViewItems be of type Microsoft.UI.Xaml.Controls.NavigationViewItem.");
}

// Get or create a wrapping container for the data
auto const nvi = [this]() {
if (navigationViewItemPool.size() > 0)
Expand Down