Cascading Styling
Cascading stying brings cascading styling feature to the MAUI. It allows define styles in different scopes separately. Uranium UI provides defining a background for a view and defining color to text colors of all labels in that view.
Usage
To define sub styles in a view scope, you can use the CascadingStyle
attached property. It allows to bind a style into a view resources. The style will be applied to all children of the view.
Simple Usage
Firstly, the namespace should be added to file:
It can be used in a style XAML like that:
Now you can use your container in a XAML page like the following example. The Label
will have the Yellow
color in your container. But remaining Labels will stay with the default color.
Nested usage
You can even use in multiple levels. The example below shows that all the frames will have the Yellow
color under MyContainer
and all the labels will be black under that frame which is under MyContainer.
When you run run the following XAML, you will see the following result:
Referencing Existing Styles
You can also reference existing styles in the CascadingStyle.Resources
property. The following example shows that using a style that is already defined and how to prevent re-writing it.
Setting StyleClass
By default StyleClass
property is not a bindable property and you can't set it in a style XAML. CascadeStyle.StyleClass
allows you set StyleClasses for other views in a style XAML. It can be used like the following example:
The following usage is enough to apply the style to all buttons under MyContainer
: