Using user selected colors and fonts
Sometimes, it is useful to use the system theme in an application UI to have a synchronous flow of colors and fonts between the operating system and the application. In these cases, we can dynamically load those values and apply them to our UI elements. This is achievable by accessing some special resource keys within the SystemColors
and SystemFonts
classes. In this recipe, we will learn how to use them.
Getting ready
Let's get started by creating a new project called CH07.SystemResourcesDemo
. Make sure you select the WPF application template from the available list.
How to do it...
We will now build an application that uses system colors and fonts. Follow these steps to proceed with it:
- Open the
MainWindow.xaml
file and insert the followingRectangle
inside theGrid
panel:
<Rectangle Height="100" Width="300"/>
- We want to fill the rectangle with the color of the desktop brush. Add the following markup to fill the background color of the rectangle...