Managing logical resources
Logical resources may be of various types, such as brushes, geometries, styles, and templates. Placing all those resources in a single file such as App.xaml
hinders maintainability. A better approach would be to separate resources of different types (or based on some other criteria) to their own files. Still, they must be referenced somehow from within a common file such as App.xaml
so they are recognized. This recipe shows how to do just that.
Getting ready
Make sure Visual Studio is up and running.
How to do it...
We'll create an application that separates its resources across multiple files for convenience and manageability:
Create a new WPF Application named
CH02.ManagingResources
.We want to create a separate file that would hold (for example) brush resources. Right-click on the Project node in Solution explorer and select Add | ResourceDictionary…:
In the Name box, type
Brushes.xaml
and click on Add.A XAML editor is opened with a
ResourceDictionary
as a rootelementVisual...