Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Silverlight
Silverlight 4 Beta
 MergedDictionaries Property
Collapse All/Expand All Collapse All
.NET Framework Class Library for Silverlight
ResourceDictionary..::.MergedDictionaries Property

[Note: This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

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

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)
Visual Basic (Declaration)
Public ReadOnly Property MergedDictionaries As PresentationFrameworkCollection(Of ResourceDictionary)
    Get
Visual Basic (Usage)
Dim instance As ResourceDictionary
Dim value As PresentationFrameworkCollection(Of ResourceDictionary)

value = instance.MergedDictionaries
C#
public PresentationFrameworkCollection<ResourceDictionary> MergedDictionaries { get; }
XAML Property Element Usage
<ResourceDictionary>
  <ResourceDictionary.MergedDictionaries>
    oneOrMoreResourceDictionaryElements
  </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

XAML Values

oneOrMoreResourceDictionaryElements

One or more explicit ResourceDictionary object elements. Each such ResourceDictionary should specify a Source value as its only attribute, and should not attempt to specify any keyed child content itself. Also, do not specify an x:Key Attribute on the merged dictionary ResourceDictionary object elements.

Property Value

Type: System.Windows..::.PresentationFrameworkCollection<(Of <(ResourceDictionary>)>)
A collection of the ResourceDictionary dictionaries that constitute the various resource dictionaries in the merged dictionaries.

Dictionaries are merged by adding a ResourceDictionary to the generic collection referenced by MergedDictionaries. A merged ResourceDictionary does not have resource elements defined within it in markup. Instead, the merged dictionary is a ResourceDictionary with no markup child elements defined (or with no elements added through code), but with a URI specified for Source. The Source designation enables the merged dictionary to come from an external source, such as "loose XAML" that is packaged with the XAP by the Page or Content build action but not compiled into the DLL (as other page-level XAML is by typical build actions). When used as a merged dictionary source, it is illegal for a XAML file that has a ResourceDictionary root to specify x:Class.

Specifying resource elements within a ResourceDictionary that also has Source specified is not supported.

Lookup behavior within the MergedDictionaries collection searches the last-added ResourceDictionary first, and the search stops as soon as a requested key is found. In other words, the retrieval logic from the collection of merged resource dictionaries is last in, first out.

Duplicate keys across the collection of merged dictionaries are not illegal. In fact, you can use multiple merged ResourceDictionary sources as part of a deliberate fallback sequence where the last referenced ResourceDictionary contains the fallbacks in case no preceding ResourceDictionary defined the key.

Merged Dictionary Lookup

Resources in a merged dictionary occupy a location in the resource lookup scope that is just after the scope of the main resource dictionary they are merged into. A resource key must be unique within any individual dictionary (including within any individual ResourceDictionary that is the source for one of the merged dictionaries). However, a key can exist multiple times in the combined set of merged dictionaries. In this case, the resource that is returned will come from the last dictionary found sequentially in the MergedDictionaries collection.

If the MergedDictionaries collection definition was defined in XAML, then the order of the merged dictionaries in the collection is the order of the elements as provided in the markup, and lookup uses the last ResourceDictionary in that order first. For example, consider the following XAML:

<UserControl.Resources>
  <ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
      <ResourceDictionary Source="rd1.xaml"/>
      <ResourceDictionary Source="rd2.xaml"/>
    </ResourceDictionary.MergedDictionaries>
  </ResourceDictionary>
</UserControl.Resources>
<!--rd1.xaml, xmlns omitted-->
<ResourceDictionary>
  <SolidColorBrush x:Key="maindialogbrush" Color="Orange"/>
</ResourceDictionary>
<!--rd2.xaml, xmlns omitted-->
<ResourceDictionary>
  <SolidColorBrush x:Key="maindialogbrush" Color="LimeGreen"/>
</ResourceDictionary>

In this example, if a resource request is made for the resource with the key keymaindialogbrush,the returned brush will be the color LimeGreen, because rd2.xaml is the last defined merged dictionary.

If a key is defined in the primary dictionary and also in one or more MergedDictionaries collection dictionaries, then the resource that is returned will come from the primary dictionary. Note that this entails that any merged dictionary is prior to the Application..::.Resources in the progression.

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker