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

WinUI 3 app crashes when NavigationViewItem IsSelected="True" and built with WindowsAppSDK 1.2.221109.1 or later #8002

Closed
j-2-3 opened this issue Dec 2, 2022 · 2 comments
Labels
area-NavigationView NavView control bug Something isn't working Crash whenever user reports a crash or app freeze no-issue-activity team-Controls Issue for the Controls team

Comments

@j-2-3
Copy link

j-2-3 commented Dec 2, 2022

Describe the bug

I have a WinUI 3 app that used to work fine up until WindowsAppSDK ver. 1.2.220930.4-preview2 but crashes with 'Value does not fall within the expected range.' unhandled exception message when built with newer WindowsAppSDK.

The issue is with preselecting NavigationViewItem via IsSelected property (set to "True") in xaml when NavigationViewItem Content is something different than simple string:
(xaml angle brackets swapped for brackets just to have it displayed correctly here)

[NavigationViewItem.Content]The text[/NavigationViewItem.Content]

works fine,

but:

[NavigationViewItem.Content]
[TextBlock Text="The text"/]
[/NavigationViewItem.Content]

does not.

Steps to reproduce the bug

  1. Create WinUI 3 app using Template Studio for WinUI 'Blank' project type and 'Self-Contained' in the Features creator tab
    (actually i think any blank WinUI app will do)
  2. Update Microsoft.WindowsAppSDK Nuget reference to version 1.2.221109.1 or 1.2.221116.1
  3. Replace MainPage.xaml content (the top level grid) with the one from the attachment
  4. Run the app in debug mode and observe the exception thrown (when run without debugger it just won't start)
    MainPage.zip

Expected behavior

It should be possible to use the NavigationViewItem IsSelected property in xaml without restrictions to the NavigationViewItem Content

Screenshots

No response

NuGet package version

Windows App SDK 1.2.1: 1.2.221116.1

Packaging type

Packaged (MSIX)

Windows version

Windows 10 version 20H2 (19042, October 2020 Update)

IDE

Visual Studio 2022

Additional context

No response

@j-2-3 j-2-3 changed the title WinUI 3 app crashes when NavigationViewItem IsSelected="True" when built with WindowsAppSDK 1.2.221109.1 or later WinUI 3 app crashes when NavigationViewItem IsSelected="True" and built with WindowsAppSDK 1.2.221109.1 or later Dec 2, 2022
@gabbybilka gabbybilka transferred this issue from microsoft/WindowsAppSDK Dec 8, 2022
@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Dec 8, 2022
@gabbybilka gabbybilka added bug Something isn't working area-NavigationView NavView control team-Controls Issue for the Controls team Crash whenever user reports a crash or app freeze and removed needs-triage Issue needs to be triaged by the area owners labels Dec 8, 2022
@github-actions
Copy link

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 4, 2023
@Fritierkelle
Copy link

Fritierkelle commented Nov 9, 2023

It looks like this issue still exists in 1.4.

Solved it by:

void winrt::App1::implementation::MainWindow::nvMainWindow_Loaded(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e)
{
winrt::Microsoft::UI::Xaml::Controls::NavigationViewItem nviStandard = nvMainWindow().FindName(winrt::to_hstring("nviStandard")).aswinrt::Microsoft::UI::Xaml::Controls::NavigationViewItem();

nvMainWindow().SelectedItem(nviStandard);

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-NavigationView NavView control bug Something isn't working Crash whenever user reports a crash or app freeze no-issue-activity team-Controls Issue for the Controls team
Projects
None yet
Development

No branches or pull requests

3 participants