Skip to content

Fix WPF sample style source reference - #819

Open
Goodness Ade (ade0003) wants to merge 2 commits into
microsoft:mainfrom
ade0003:fix-wpf-style-resource
Open

Goodness Ade (ade0003) wants to merge 2 commits into
microsoft:mainfrom
ade0003:fix-wpf-style-resource

Conversation

@ade0003

@ade0003 Goodness Ade (ade0003) commented Oct 25, 2026 •

Copy link
Copy Markdown

Related to #792.

Summary: Corrected the navigation window's style resource reference in MainWindow.xaml by replacing the reference to CustomNavWindowStyle with NavWindowKeyboardAccessibleStyle.

I tested it by inspecting the referenced style definition and confirming the resource key, I also reviewed the git diff and checked the updated reference.

Microsoft Reviewers: Open in CodeFlow

@HSU-YU-MING

Copy link
Copy Markdown

Thanks for picking this up. I built the sample with this change applied: the window now opens, but NavWindowKeyboardAccessibleStyle brings in a second undefined resource, and the app still crashes once it's reached.

NavigationWindowKeyboardAccessibleStyle.xaml:

  • line 632: NavWindowKeyboardAccessibleStyle sets Template to NavigationWindowTemplateKey
  • line 579: that template's forward button uses NavigationWindowForwardButtonStyle
  • line 450: which sets FocusVisualStyle to {StaticResource NavButtonFocusVisualStyle}

NavButtonFocusVisualStyle isn't defined anywhere in the sample. Reading the forward button's FocusVisualStyle after the window loads throws

InvalidOperationException: '{DependencyProperty.UnsetValue}' is not a valid value for property 'FocusVisualStyle'.

and takes the process down. WPF reads that property when the button gets keyboard focus, so in practice it should surface when you Tab to the forward button — ironic for the keyboard-accessible style. The back button style next to it doesn't set FocusVisualStyle (it draws its focus indicator in its own template), so removing the setter on line 450, or defining NavButtonFocusVisualStyle, should be enough.

Found with XamlKeys, a static checker for XAML resource keys I'm working on.

@ade0003

Copy link
Copy Markdown
Author

Hey thanks for catching this! I removed the undefined NavButtonFocusVisualStyle setter like you suggested

@ade0003

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants