Gets or sets the locally-defined resource dictionary.
Assembly: PresentationFramework (in PresentationFramework.dll)
Resource dictionaries that can be defined completely or partially in Extensible Application Markup Language (XAML) are typically created as a property element, and are typically on the root element for any individual page or for the application. Placing the resource dictionary at this level makes it easier to find from individual child elements in the page (or from any page, in the application case). In most application scenarios, we recommend that styles be defined as object elements within a resource dictionary, or be defined as external resources so that the entire style resource can be self-contained (this approach helps separate designer responsibilities from developer responsibilities by separating the physical files that need to be edited).
Note that this property returns only the resource dictionary declared directly within that element. This is different than the actual resource lookup process, where a child element can access any of the resources defined in each parent element, searching recursively upwards.
Resources can also be referenced by code from within the collection, but be aware that resources created in XAML will definitely not be accessible until after Loaded is raised by the element that declares the dictionary. In fact, resources are parsed asynchronously and not even the Loaded event is an assurance that you can reference a XAML defined resource. For this reason you should generally only access XAML defined resources as part of run-time code, or through other XAML techniques such as styles or resource extension references for attribute values. When you access resources through code, it is essentially equivalent to a reference made from XAML.
The underlying ResourceDictionary supports the methods required to add, remove or query resources from within the collection by using code. The property is settable to support the scenario of completely replacing the resources collection of an element to be a new or different ResourceDictionary.
Notice that the XAML syntax shown does not include an element for the ResourceDictionary. This is an example of implicit collection syntax; a tag representing the collection element can be omitted. The elements that are added as items to the collection are specified instead. For more information about implicit collections and XAML, see XAML Syntax In Detail. One case where a ResourceDictionary is still specified explicitly as an element is if you are introducing a merged dictionary, in which case there are typically no child elements for that ResourceDictionary. For details, see Merged Resource Dictionaries.
Legacy Code Example
Available since 3.0
Available since 2.0
Windows Phone Silverlight
Available since 7.0