Blog

posts from 2021

XAML Lightweight styling done right

0 Comments
By Fons Sonnemans, 11-jan-2021

You can customize the appearance of your apps in many ways by using the XAML framework. Styles let you set control properties and reuse those settings for a consistent appearance across multiple controls.

With Lightweight styling you override the system brushes, and the color override will affect all controls that reference that brush. Although this is called styling you are not defining a style. You just create a ResourceDictionary with a ThemeDictionary in which you override the system brushes.

<Page.Resources>
    <ResourceDictionary>
        <ResourceDictionary.ThemeDictionaries>
            <ResourceDictionary x:Key="Light">
                 <SolidColorBrush x:Key="ButtonBackground"                                   
                                  Color="Transparent"/>
                 <SolidColorBrush x:Key="ButtonForeground" 
                                  Color="MediumSlateBlue"/>
                 <SolidColorBrush x:Key="ButtonBorderBrush"
                                  Color="MediumSlateBlue"/>
            </ResourceDictionary>
        </ResourceDictionary.ThemeDictionaries>
    </ResourceDictionary>
</Page.Resources>/>

These overriden system brushes make a normal Button control transparent with a purple border and text (content).

READ MORE

All postings/content on this blog are provided "AS IS" with no warranties, and confer no rights. All entries in this blog are my opinion and don't necessarily reflect the opinion of my employer or sponsors. The content on this site is licensed under a Creative Commons Attribution By license.