Resources
dictionary which is available on every style and control and then refer to these resources elsewhere.App.xaml
/App.axaml
:Window
or UserControl
: the resource will be available to the Window
/UserControl
and its children:{DynamicResource}
markup extensions, e.g.:StaticResource
markup extension which has a few limitations with respect to DynamicResource
:StaticResource
doesn't need to add an event handler to listen for changes in resources which means it uses slightly less memory.DynamicResource
or StaticResource
until a resource with the requested key is found. This means that resources can be "overridden" in sub-trees of the application, for example:Border
's background will be Orange
because its parent StackPanel
has "overridden" the Warning
resource from the Yellow
declared on the UserControl
.Resources
property on each control and style is of type ResourceDictionary
. Resource dictionaries can also include other resource dictionaries by making use of the MergedDictionaries
property. To include a resource dictionary in another you can use the ResourceInclude
class, e.g.:AnotherResourceDictionary
is a XAML file with a root of ResourceDictionary
and is included as an asset in the application.DynamicResource
or StaticResource
until a resource with the requested key is found. However the presence of styles and merged dictionaries complicates this somewhat. The precedence is as follows:Border
control would follow the order indicated in []
brackets: