Using resources and templates

When building graphical user interfaces, you will often want to use a resource, such as a brush, to paint the background of controls. These resources can be defined in a single place and shared throughout the app.

Sharing resources

In the Solution Explorer window, double-click on the App.xaml file.

Add the following markup inside the existing <Application> element:

 <Application.Resources> <LinearGradientBrush x:Key="rainbow"> <GradientStop Color="Red" Offset="0" /> <GradientStop Color="Orange" Offset="0.1" /> <GradientStop Color="Yellow" Offset="0.3" /> <GradientStop Color="Green" Offset="0.5" /> <GradientStop Color="Blue" Offset="0.7" /> <GradientStop Color="Indigo" Offset="0.9" /> <GradientStop Color="Violet" Offset="1" ...

Get C# 7 and .NET Core: Modern Cross-Platform Development - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.