Using shared resources
When building graphical UIs, 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
.Visual Studio Code and JetBrains Rider do not have project item templates for MAUI. You can create this item using the CLI, as shown in the following command:
dotnet new maui-dict-xaml --name Northwind.xaml
- Add markup inside the existing
ResourceDictionary
element to define a linear gradient brush with a key ofRainbow...