What's the proper way to set Foreground on CheckBox using Lightweight styling? #1214
-
With the Lightweight styling introduced with Uno 4.10 I can no longer set the
I'd like to avoid writing 18 lines of code in my pages that need this. I assume I can do this using a style however I don't understand how to do that. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 12 replies
-
Good catch, CheckBox is a good example to highlight in the docs as it is a bit of a special case where Foreground/Background don't apply as you might expect, and definitely something that we missed when talking about breaking changes. If you are attempting to use the Foreground property to manage the color of the checkmark/indeterminate glyph, you'll have to override the resources like you would if you were using the Fluent version of the CheckBox style. See a similar question here In the case of using an existing brush, your XAML should look something like: <CheckBox Content="Checked">
<CheckBox.Resources>
<StaticResource x:Key="CheckBoxGlyphForegroundChecked" ResourceKey="OnPrimaryBrush" />
<StaticResource x:Key="CheckBoxGlyphForegroundCheckedPointerOver" ResourceKey="OnPrimaryBrush" />
<StaticResource x:Key="CheckBoxGlyphForegroundCheckedPressed" ResourceKey="OnPrimaryBrush" />
<StaticResource x:Key="CheckBoxGlyphForegroundChecked" ResourceKey="OnPrimaryBrush" />
<!-- ... -->
</CheckBox.Resources>
</CheckBox> Although, in the case of the Glyph Foreground, those should already be all OnPrimaryBrush It's a bit verbose, I know, but we're trying to follow the standards from Fluent styles. There is work underway to be able to define a set of Resources as an attached property that you can use as a Setter on a custom Style so you can re-use the same CheckBox style with all the overridden resources throughout your app. If this is something you want to be done globally or at a Page-level, you can define these StaticResource aliases in the App/Page Resources instead of on the specific CheckBox. There's also work starting around a simpler way to override the material colors at any scope. So you will be able to say "just for this CheckBox, use X as PrimaryColor/OnPrimaryColor/SurfaceColor/etc." You are correct that the documentation should show a case like this where you can alias existing brushes as part of your lightweight styling overrides. |
Beta Was this translation helpful? Give feedback.
Ok so your suggestion of redefining a new
SolidColorBrush
using aThemeResource
reference on the color is what I ended up doing because it avoids duplicating the overrides per theme.Thanks for that.