-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Updating WinUI properties via resources does not take effect #7820
Description
Description
Setting certain properties on Windows does not directly update the control but rather the resources. For example, Button.BorderWidth. As a result, the property makes no visible change until something triggers the OS theme to change.
The reason this happens is that properties are set in the styles using {ThemeResource} which is just a {StaticResource} tied to a theme. This means that it is just a read once thing - unless the theme changes.
There is a workaround and that is to toggle the theme, but a "real fix" is coming in https://dev.azure.com/microsoft/OS/_workitems/edit/39897009/
This fix I believe for the interim will basically trigger theme updates without requiring the toggling of the theme. However, the end result is basically the same, the theme is refreshed for he entire control. This totally can change but for now this will make things work.
Related to:
- Unable to un-set values on Windows #7803
- Calling ClearValue if a color is null on WinUI is incorrect behavior #4356
- Entry background not accurate when changed with Triggers #5084
And related to WASDK:
- Question: Best way to force reevaluate of ThemeResource binding microsoft/microsoft-ui-xaml#5457
- Updating ResourceDictionary in code behind doesn't fire change notification microsoft/microsoft-ui-xaml#4443
- Proposal: Add Application.ApplyThemes method microsoft/microsoft-ui-xaml#4651
Version with bug
6.0 (current)
Last version that worked well
Unknown/Other
Affected platforms
Windows
Affected platform versions
All
Did you find any workaround?
There is a workaround and that is to get the native control and toggle the RequestedTheme.
Relevant log output
No response