ResourceDictionary.MergedDictionaries Property

Definition

Gets a collection of the ResourceDictionary dictionaries that constitute the various resource dictionaries in the merged dictionaries.

public:
 property IVector<ResourceDictionary ^> ^ MergedDictionaries { IVector<ResourceDictionary ^> ^ get(); };
IVector<ResourceDictionary> MergedDictionaries();
public IList<ResourceDictionary> MergedDictionaries { get; }
var iVector = resourceDictionary.mergedDictionaries;
Public ReadOnly Property MergedDictionaries As IList(Of ResourceDictionary)
<ResourceDictionary>
  <ResourceDictionary.MergedDictionaries>
    oneOrMoreResourceDictionaryElements
  </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

Property Value

A list collection of the ResourceDictionary dictionaries that constitute the various resource dictionaries in the merged dictionaries.

Examples

The starting Microsoft Visual Studio templates for a UWP app using C++, C#, or Visual Basic include a MergedDictionaries node in the app.xaml file. This references a separate XAML ResourceDictionary in the project that contains some basic control template definitions. You can modify the XAML within the ResourceDictionary in order to customize the appearance of your controls.

<Application
    ....
>
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Common/StandardStyles.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

Remarks

Setting a MergedDictionaries value enables you to share a ResourceDictionary XAML file amongst several pages, or also as a common file you might add to multiple app projects. This provides a useful factoring and reuse technique for resources from a development and design standpoint. You typically include the XAML file as a Content item as part of the project and app manifest.

The keyed resources in any MergedDictionaries XAML do not have to be unique versus the keys as found in the primary ResourceDictionary for Application.Resources or FrameworkElement.Resources, and the lookup order for keys will look in the primary dictionary first. This enables a technique whereby you can override any key value obtained from within MergedDictionaries XAML files, but you could also have the merged dictionaries available as a fallback or as a general set of non-customized resources.

You can include more than one ResourceDictionary in a MergedDictionaries set in order to provide a fallback sequence even within the MergedDictionaries set.

For more info on how to use MergedDictionaries and the resource lookup sequence, see ResourceDictionary and XAML resource references.

ThemeDictionaries is a related property that also merges additional XAML ResourceDictionary sources into the overall keyed resource set, where the scenario is for providing theme-related resources for controls.

Changing the contents of the collection of ResourceDictionary items for MergedDictionaries is not a common scenario. Generally you establish the collection contents in XAML and don't change it at runtime. There aren't many scenarios where you would access the collection itself in run-time code. Usually you rely on the built-in resource lookup that happens at XAML load time, or you query the relevant Application.Resources or FrameworkElement.Resources collections that can reference resources by key, including the merged resources.

Applies to

See also