question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[UWP] Allow using XAML Brush theme resources for host config color options

See original GitHub issue

Today, hosts have to manually change their host config when the theme (accent color) or high contrast changes, since colors are all specified with absolute values in the host config.

	"containerStyles": {
		"default": {
			"foregroundColors": {
				"default": {
					"default": "#FF333333",
					"subtle": "#EE333333"
				},
				"accent": {
					"default": "#FF2E89FC",
					"subtle": "#882E89FC"
				},

Instead, it would be much easier for UWP hosts if they could just provide a XAML theme resource brush, which automatically updates when themes change, which is what apps use in their own normal UI, like seen below…

<TextBlock Foreground="{ThemeResource AccentBrush}"/>

The host config could be modified to be the following

	"containerStyles": {
		"default": {
			"foregroundColors": {
				"default": {
					"default": "#FF333333",
					"subtle": "#EE333333",
					"uwp": {
						"default.themeresource": "NormalBrush",
						"subtle.themeresource": "SubtleBrush"
					}
				},
				"accent": {
					"default": "#FF2E89FC",
					"subtle": "#882E89FC",
					"uwp": {
						"default.themeresource": "AccentBrush",
						"subtle.themeresource": "AccentSubtleBrush"
					}
				},

And if the uwp.*.themeresource value is specified, the UWP renderer assigns the theme resource rather than the absolute color value.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:14 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
mdtaukcommented, Jun 23, 2018

I think for sure it would be something specific to the UWP rendering of a card, as it relies on being able to insert values provided either by the System’s settings/config or resources stored within the App’s resources.

So how you implement that in the HostConfig spec, would probably require a prefix. If it is kept to UWP resources only, then a uwp:default type value, which is ignored by other renderers, could be done. Or broaden it out slightly. system:default where each renderer can either provide a value or assign it from system provided colours. iOS has a set of standard colours in its UIKit API I believe. I can’t speak to Android’s API.

1reaction
dclauxcommented, Jun 11, 2018

I’m not sure this needs to be an official, documented feature. It breaks the portability of HostConfig which is the reason HostConfig exists in the first place.

I get why this is convenient and it seems to me that it’s OK to do it, but I think it should remain a UWP-renderer-specific feature. Every platform has its own model for theme colors; I don’t think we want to end up having all platforms’ models explicitly supported in HostConfig.

Also, I would go one step further:

"containerStyles": {
	"default": {
		"foregroundColors": {
			"default": {
				"default": "#FF333333",
				"subtle": "#EE333333",
				"uwp": {
					"default": "ThemeResource(NormalBrush)",
					"subtle": "ThemeResource(SubtleBrush)"
				}
			},
			"accent": {
				"default": "#FF2E89FC",
				"subtle": "#882E89FC",
				"uwp": {
					"default": "ThemeResource(AccentBrush)",
					"subtle": "ThemeResource(AccentSubtleBrush)"
				}
			},

This way you decouple the property from its format. Otherwise you might end up with multiple “default.XXX” in the long run.

Read more comments on GitHub >

github_iconTop Results From Across the Web

XAML theme resources - Windows apps
The XAML color ramp and theme-dependent brushes. The combined set of colors for "Light", "Dark", and "HighContrast" themes make up the Windows ...
Read more >
Using the Visual Layer with XAML - UWP applications
Learn techniques for using the Visual Layer API's in combination with existing XAML content to create advanced animations and effects.
Read more >
Using a Dynamic System Accent Color in UWP
This article describes an algorithm that allows individual pages in a XAML UWP app to override the system accent color.
Read more >
Set theme color into SolidColorBrush resource in UI for WPF
I am trying to set theme (Fluent) AlternativeBrush into SolidColorBrush resource. I am facing error #FFF2F2F2' is not a valid value for ...
Read more >
Telerik Named Brushes - Telerik UI for Universal Windows ...
It is designed to allow developers to easily override the default resources used in the default themes. This class exposes three static properties:....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found