-
Notifications
You must be signed in to change notification settings - Fork 782
Description
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
- Add a
ButtonwithStyle="{ThemeResource TitleBarPaneToggleButtonStyle}"to a page. - Add
IsEnabled="False"to the button. - 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
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
Type
Projects
Status