Skip to content

Add default case with exception to navigation switch statement - #6252

Merged
Niels Laute (niels9001) merged 2 commits into
niels9001/template-updatesfrom
copilot/sub-pr-6207-again
Feb 25, 2026
Merged

Add default case with exception to navigation switch statement#6252
Niels Laute (niels9001) merged 2 commits into
niels9001/template-updatesfrom
copilot/sub-pr-6207-again

Conversation

Copilot AI commented Feb 25, 2026

Copy link
Copy Markdown
Contributor

The NavView_SelectionChanged handler in the NavigationApp C# template had no fallback for unrecognized NavigationViewItem tags, silently swallowing unknown navigation items.

Changes

  • MainWindow.xaml.cs: Added default case to the switch (item.Tag) block that throws InvalidOperationException with the unknown tag value, making misconfigurations immediately visible at runtime.
switch (item.Tag)
{
    case "home":
        NavFrame.Navigate(typeof(HomePage));
        break;
    case "about":
        NavFrame.Navigate(typeof(AboutPage));
        break;
    default:
        throw new InvalidOperationException($"Unknown navigation item tag: {item.Tag}");
}

A microsoft employee must use /azp run to validate using the pipelines below.

WARNING:
Comments made by azure-pipelines bot maybe inaccurate.
Please see pipeline link to verify that the build is being ran.

For status checks on the main branch, please use TransportPackage-Foundation-PR
(https://microsoft.visualstudio.com/ProjectReunion/_build?definitionId=81063&_a=summary)
and run the build against your PR branch with the default parameters.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…tch statement

Co-authored-by: niels9001 <9866362+niels9001@users.noreply.github.com>
Copilot AI changed the title [WIP] Apply changes based on feedback for temp update PR Add default case with exception to navigation switch statement Feb 25, 2026
@niels9001
Niels Laute (niels9001) marked this pull request as ready for review February 25, 2026 09:36
@niels9001
Niels Laute (niels9001) merged commit 7db59da into niels9001/template-updates Feb 25, 2026
1 check passed
@niels9001
Niels Laute (niels9001) deleted the copilot/sub-pr-6207-again branch February 25, 2026 09:36
Niels Laute (niels9001) added a commit that referenced this pull request Feb 25, 2026
* Adding TitleBar and .ico

* Adding the ContentDialog ItemTemplate

* Adding NavigationView template

* Missed a csharp template and added

* Push

* Update WinAppSdk.CSharp.DotnetNewTemplates.csproj

* Clean up navview project

* Update dev/VSIX/ProjectTemplates/Desktop/CSharp/NavigationApp/Pages/HomePage.xaml.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update dev/VSIX/ProjectTemplates/Desktop/CSharp/NavigationApp/Pages/AboutPage.xaml.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update dev/VSIX/ProjectTemplates/Desktop/CSharp/NavigationApp/Pages/SettingsPage.xaml.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update dev/VSIX/ProjectTemplates/Desktop/CSharp/NavigationApp/App.xaml.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update dev/VSIX/ItemTemplates/Neutral/CSharp/ContentDialog/ContentDialog.xaml.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update dev/VSIX/ProjectTemplates/Desktop/CSharp/NavigationApp/MainWindow.xaml.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Add default case with exception to navigation switch statement (#6252)

* Initial plan

* Add default case throwing InvalidOperationException in navigation switch statement

Co-authored-by: niels9001 <9866362+niels9001@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: niels9001 <9866362+niels9001@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: niels9001 <9866362+niels9001@users.noreply.github.com>
Dinah Xiaoman G (DinahK-2SO) pushed a commit that referenced this pull request Apr 20, 2026
* Adding TitleBar and .ico

* Adding the ContentDialog ItemTemplate

* Adding NavigationView template

* Missed a csharp template and added

* Push

* Update WinAppSdk.CSharp.DotnetNewTemplates.csproj

* Clean up navview project

* Update dev/VSIX/ProjectTemplates/Desktop/CSharp/NavigationApp/Pages/HomePage.xaml.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update dev/VSIX/ProjectTemplates/Desktop/CSharp/NavigationApp/Pages/AboutPage.xaml.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update dev/VSIX/ProjectTemplates/Desktop/CSharp/NavigationApp/Pages/SettingsPage.xaml.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update dev/VSIX/ProjectTemplates/Desktop/CSharp/NavigationApp/App.xaml.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update dev/VSIX/ItemTemplates/Neutral/CSharp/ContentDialog/ContentDialog.xaml.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update dev/VSIX/ProjectTemplates/Desktop/CSharp/NavigationApp/MainWindow.xaml.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Add default case with exception to navigation switch statement (#6252)

* Initial plan

* Add default case throwing InvalidOperationException in navigation switch statement

Co-authored-by: niels9001 <9866362+niels9001@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: niels9001 <9866362+niels9001@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: niels9001 <9866362+niels9001@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants