Using shared resources
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. Resources can be defined at the following levels and shared with everything at that level or lower:
- Application
- Page
- Control
Defining resources to share across an app
A good place to define shared resources is at the app level, so let’s see how to do that:
- In the
Resources
folder, in theStyles
folder, add a new .NET MAUI Resource Dictionary (XAML) project item namedNorthwind.xaml
. - Add markup inside the existing
ResourceDictionary
element to define a linear gradient brush with a key ofrainbow
, as shown highlighted in the following markup:<?xml version="1.0" encoding="utf-8" ?> <ResourceDictionary xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns...