Skip to content

Cannot find a Resource with the Name/Key TitleBarPaneToggleButtonForegroundDisabled #10739

@SuGar0218

Description

@SuGar0218

Describe the bug

Set IsEnabled=false on a Button with Style="{ThemeResource TitleBarPaneToggleButtonStyle}", and an unhandled exception is thrown with message "Cannot find a Resource with the Name/Key TitleBarPaneToggleButtonForegroundDisabled".

Why is this important?

Sometimes disabling a element cannot be replaced with hiding it. IsEnabled is a commonly used property, but setting IsEnabled causes exception.

In my project, I want to show a ContentDialog and disable elements behind, which is of help to enhance visual effect.

Steps to reproduce the bug

  1. Add a Button with Style="{ThemeResource TitleBarPaneToggleButtonStyle}" to a page.
  2. Add IsEnabled="False" to the button.
  3. Run the application in debug mode (F5).
<Button
    IsEnabled="False"
    Style="{ThemeResource TitleBarPaneToggleButtonStyle}" />

Actual behavior

After the application launched, Visual Studio shows an unhandled exception in App.g.i.cs at here:

UnhandledException += (sender, e) =>
{
    if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
};

The parameter e has the message "Cannot find a Resource with the Name/Key TitleBarPaneToggleButtonForegroundDisabled".

Expected behavior

There should not be any exceptions and the button should be disabled normally.

Screenshots

Image

NuGet package version

WinUI 3 - Windows App SDK 1.7.3: 1.7.250606001

Windows version

Windows 11 (24H2): Build 26100

Additional context

In Visual Studio, I pressed F12 and found the definitions of TitleBarPaneToggleButtonStyle and TitleBarPaneToggleButtonBackgroundDisabled.

TitleBarPaneToggleButtonBackgroundDisabled is used in VisualStateManager of TitleBarPaneToggleButtonStyle.

But TitleBarPaneToggleButtonBackgroundDisabled does exist in generic.xaml:

<ResourceDictionary x:Key="Default">
    <StaticResource x:Key="TitleBarPaneToggleButtonBackgroundDisabled" ResourceKey="ControlFillColorDisabledBrush" />
</ResourceDictionary>
<ResourceDictionary x:Key="HighContrast">
    <StaticResource x:Key="TitleBarPaneToggleButtonBackgroundDisabled" ResourceKey="ControlFillColorDisabledBrush" />
</ResourceDictionary>
<ResourceDictionary x:Key="Light">
    <StaticResource x:Key="TitleBarPaneToggleButtonBackgroundDisabled" ResourceKey="ControlFillColorDisabledBrush" />
</ResourceDictionary>

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingfixed-internallyThis bug has been fixed, and the fix will be shipped in the next version of WinUI 3.needs-triageIssue needs to be triaged by the area owners💖community-contribution

Type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions