Replies: 2 comments 5 replies
-
With the current inability of scoping color overrides into styles for easy reuse, this seems like a primordial feature. |
Beta Was this translation helpful? Give feedback.
0 replies
-
So, for now we named the class as Control levelPage level |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The Problem
An application may be designed around a common theme of colors for branding and other purposes but may still have a need to include a set of custom colors that are used in specific part of an application. For example, an e-commerce app may have a primary color of Blue for its branding so, implicitly, all themed components will follow that color theme of using Blue as its primary color. However, something like the Checkout page may require some components like a "Pay Now" button to be themed as though the primary color were Green instead of Blue. This could initially be achieved by simply setting the Background of the specific button to Green but then we run into issues where certain brushes used for the visual states of the button may still use the original Blue primary brush as its source and leads to visual issues. There can also be problems with legibility if the Foreground color of the button contrasts well with the default primary color but not with this new custom Background color that you may want to use. Currently, this would require a new style to be created in order to re-template the component and use alternative colors for the visual states.
Intermediate Solution (Lightweight Styling)
How this would be solved currently in WinUI would be to utilize Lightweight Styling. The styles within Themes and Toolkit support, or will soon support, Lightweight Styling and define specific resource keys that can be overridden in order to customize how a component looks in all visual states. This, however, is a very verbose and cumbersome method of customization. In the case of our example e-commerce application, we would need to redefine each of the Background and Foreground resources for each visual state that we want to support. An example usage for Lightweight Styling would look something like:
Proposed Solution (Scoped Color Overrides)
It would be beneficial to be able to declare certain "color sets" that can be generated around specific "seed" colors and we could then specify which color set a specific component or page should use when resolving the color theme resources. We could then create a custom set of colors, keyed as something like "PayNow" where Green was the PrimaryColor and White would be the OnPrimaryColor. The resulting XAML could then look something like
The color sets would be declared within the bootstrapping of the current theme. Taking the current
MaterialTheme
as an example inside of theAppResources.xaml
, we could "register" they key color sets like so:We would essentially allow people to be defining multiple ColorPaletteOverrides and we would handle the work of re-initializing the Brushes based on the provided "color set" (override palette) within the context of the control that has the
ColorSet
property declared.Seeding
Going a step further, we could introduce the ability to simply provide an initial seed color for the custom color sets and have the rest of the override palette generated at build time based on that color. We would have it work similar to the way you use the Material Theme Builder
So the MaterialTheme bootstrapping of color sets could be simplified even further and look something like:
In this case we would define custom ResourceDictionaries called
ColorSet
that would accept aSeed
and use the algorithms from the theme builders to generate the appropriate colors.Questions
MaterialTheme.ColorSetDictionaries
, I figured follow suit withResourceDictionaries.MergedDictionaries
andResourceDictionaries.ThemeDictionaries
Beta Was this translation helpful? Give feedback.
All reactions