-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing Button resources #10442
base: main
Are you sure you want to change the base?
Fixing Button resources #10442
Conversation
@@ -329,8 +336,18 @@ | |||
<SolidColorBrush x:Key="ButtonForegroundPointerOver" Color="{StaticResource TextFillColorPrimary}" /> | |||
<SolidColorBrush x:Key="ButtonForegroundPressed" Color="{StaticResource TextFillColorSecondary}" /> | |||
<SolidColorBrush x:Key="ButtonForegroundDisabled" Color="{StaticResource TextFillColorDisabled}" /> | |||
<!--<SolidColorBrush x:Key="ButtonBorderBrush" Color="{StaticResource ControlElevationBorder}" />--> | |||
<!--<SolidColorBrush x:Key="ButtonBorderBrushPointerOver" Color="{StaticResource ControlElevationBorder}" />--> | |||
<LinearGradientBrush x:Key="ButtonBorderBrush" MappingMode="Absolute" StartPoint="0,0" EndPoint="0,3"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should just re-use ControlElevationBorderBrush. I don't think there is any reason to duplicate this complicated Brush. Otherwise, it is duplicate code and any updates would then have to be done multiple places -- bad practice.
WinUI does the same: https://github.com/microsoft/microsoft-ui-xaml/blob/589ced40542b9b4de2fddf0e58a1e3eecd164e2f/src/controls/dev/CommonStyles/Button_themeresources.xaml#L26-L27
I would ALWAYS review WinUI when making these types of changes.
Edit: I believe the below syntax works in WPF. I spend more time with more modern XAML frameworks so this needs to be tested.
<StaticResource
x:Key="ButtonBorderBrush"
ResourceKey="ControlElevationBorderBrush" />
<StaticResource
x:Key="ButtonBorderBrushPointerOver"
ResourceKey="ControlElevationBorderBrush" />
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that works, but let me give it a try.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get the following error when I do the above. However, I have seen this syntax in other places, but the StaticExtension there is a subclass of StaticResourceExtension for that : https://github.com/Kinnara/ModernWpf/blob/master/ModernWpf/Markup/StaticResourceExtension.cs
After that they can use the above syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not actually sure what is going on here. The existing StaticResourceExtensions has this constructor as well:
wpf/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/StaticResourceExtension.cs
Lines 35 to 39 in a792086
public StaticResourceExtension( | |
object resourceKey) | |
{ | |
ArgumentNullException.ThrowIfNull(resourceKey); | |
_resourceKey = resourceKey; |
Either way, this is useful functionality. Perhaps it is a good idea to support it in Vanilla WPF as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was looking further, the error seems to be thrown by a Debug.Assert statement here :
wpf/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlRecordWriter.cs
Line 563 in a792086
Debug.Assert(!InStaticResourceSection, "We do not support x:Key within a StaticResource Section"); |
I don't know why this is here. I will open up an issue for this and try to find out what's the reasoning behind this.
By the way, would you know how this works ? Does it create a copy of the actual resource or is just a reference to the original resource ?
<!--<SolidColorBrush x:Key="AccentButtonBorderBrush" Color="{DynamicResource AccentControlElevationBorder}" />--> | ||
<!--<SolidColorBrush x:Key="AccentButtonBorderBrushPointerOver" Color="{DynamicResource AccentControlElevationBorder}" />--> | ||
<SolidColorBrush x:Key="AccentButtonForegroundDisabled" Color="{StaticResource TextOnAccentFillColorDisabled}" /> | ||
<LinearGradientBrush x:Key="AccentButtonBorderBrush" MappingMode="RelativeToBoundingBox" StartPoint="0,1" EndPoint="0,0"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as for ButtonBorderBrush, ButtonBorderBrushPointerOver -- re-use the pre-existing brushes.
Fixes # #9886
Description
Button styles were using the common / Fluent brushes directly rather than Button's control brushes like ButtonBorderBrush, ButtonBorderBrushPointerOver, etc.
In this PR, I have fixed the Button styles to use the Button control brushes correctly.
Customer Impact
Developers will be able to modify the Button control brushes without affecting other controls.
Regression
No
Testing
Local testing
Risk
No
Microsoft Reviewers: Open in CodeFlow