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 or an instance of a class to perform custom conversions. These resources can be defined in a single place and shared throughout the app.
Sharing resources
A good place to define shared resources is at the app level, so let's see how to do that.
- In Solution Explorer, open the
App.xaml
file. - Add the following markup inside the existing
Application
element to define a linear gradient brush with a key ofrainbow
, as shown highlighted in the following markup:<Application x:Class="FluentUwpApp.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:FluentUwpApp"> <Application.Resources> <LinearGradientBrush x:Key="rainbow"> ...