ResourceDictionary ResourceDictionary ResourceDictionary Class

Defines a repository for XAML resources, such as styles, that your app uses. You define the resources in XAML and can then retrieve them in XAML using the {StaticResource} markup extension and {ThemeResource} markup extension s. You can also access resources with code, but that is less common.

Syntax

Declaration

public class ResourceDictionarypublic class ResourceDictionaryPublic Class ResourceDictionary
<ResourceDictionary>
  oneOrMoreResources
</ResourceDictionary>

Inheritance Hierarchy

Remarks

A resource dictionary is a repository for XAML resources, such as styles, that your app uses. You define the resources in XAML and can then retrieve them in XAML using the {StaticResource} markup extension and {ThemeResource} markup extension s. You can also access resources with code, but that is less common. You can use resources to enforce that certain values such as brush colors or pixel measurements are used consistently throughout your app. For more info on using resource dictionaries effectively, see ResourceDictionary and XAML resource references.

Uses of ResourceDictionary elements

The ResourceDictionary type is used as the value of two properties, Resources and Resources, that are important to the overall structure of a Windows Store app. XAML files that you get from a starting project template for an app will start with initial values for Resources, and the app.xaml file might start with initial values for Resources. Exactly what resources are defined there depends on which project starting template you're using.

This XAML shows the use of a Resources property. In this case the FrameworkElement is a Page. There is no ResourceDictionary element subordinate to the Page.Resources property element, but its presence is implied; for more info see the "Notes on XAML syntax" section below. The XAML places a Style into the ResourceDictionary with an x:Key attribute value of "TextBlockStyle1". Further down in the XAML, the {StaticResource} markup extension references the Style in the resource dictionary to provide a value for the Style property of the TextBlock element.

The Style as shown does not actually apply any styling to the TextBlock, but you can add Style properties in Microsoft Visual Studio. You can then use the Style resource as often as you like on the page to enforce uniformity.

You can use Microsoft Visual Studio to create resource dictionaries. This example was created with these steps: put a TextBlock on the design surface, right click, choose Edit Style / Create Empty, then "This document" to define the new resource in Page.Resources.

<Page
    x:Class="ResourceDictionary_example.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:ResourceDictionary_example"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    <Page.Resources>
        <Style x:Key="TextBlockStyle1" TargetType="TextBlock"/>
    </Page.Resources>

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <TextBlock Style="{StaticResource TextBlockStyle1}" Text="TextBlock"/>
    </Grid>
</Page>

This XAML, from the AppPage.xaml file of the AtomPub sample, shows the use of an Resources property. The XAML places two Style elements into the resource dictionary, making them available throughout the application.

<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    x:Class="AtomPub.App"
    RequestedTheme="Light" >
    <Application.Resources>
        <ResourceDictionary>
            <Style x:Key="TitleStyle" TargetType="TextBlock">
                <Setter Property="Foreground" Value="#707070"/>
                <Setter Property="FontFamily" Value="Segoe UI Light"/>
                <Setter Property="FontSize" Value="16"/>
            </Style>
            <Style x:Key="H1Style" TargetType="TextBlock">
                <Setter Property="Foreground" Value="#212121"/>
                <Setter Property="FontFamily" Value="Segoe UI Semilight"/>
                <Setter Property="FontSize" Value="26.667"/>
                <Setter Property="Margin" Value="0,0,0,25"/>
            </Style>
            ...
        </ResourceDictionary>
    </Application.Resources>
</Application>

This XAML from file MainPage.xaml uses the {StaticResource} markup extension to access the TitleStyle and H1Style styles:


    ...
    <!-- Header -->
    <StackPanel x:Name="Header" Grid.Row="0">
        <StackPanel Orientation="Horizontal">
            ...
            <TextBlock Text="Windows SDK Samples" VerticalAlignment="Bottom" Style="{StaticResource TitleStyle}" TextWrapping="Wrap"/>
        </StackPanel>
        <TextBlock x:Name="FeatureName" Text="Add Feature Name" Style="{StaticResource H1Style}" TextWrapping="Wrap"/>
    </StackPanel>
     ...

You can factor resources into their own XAML file by using ResourceDictionary as the root element of the file. You can then include those resources in a Resources or Resources resource dictionary. To do this you use the MergedDictionaries property or the ThemeDictionaries property of the ResourceDictionary element.

This file, Common/Styles1.xaml, defines Style resources using ResourceDictionary as the root element:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Style x:Key="TitleTextStyle" TargetType="TextBlock">
        <Setter Property="FontFamily" Value="Segoe UI Light"/>
        <Setter Property="FontSize" Value="16"/>
    </Style>
    <Style x:Key="HeaderTextStyle" TargetType="TextBlock">
        <Setter Property="FontFamily" Value="Segoe UI Semilight"/>
        <Setter Property="FontSize" Value="26.667"/>
        <Setter Property="Margin" Value="0,0,0,25"/>
    </Style>
    ...
</ResourceDictionary>

Now suppose there is another file, Common/Styles2.xaml that similarly defines Style resources. This XAML shows how to merge the resources in those two files using the MergedDictionaries property to create an Resources resource dictionary. The XAML also defines two further Style resources and merges them with the resources from the two files.

<Application
    .... >
    <Application.Resources>
        <ResourceDictionary>
            <Style x:Key="ErrorStyle" TargetType="TextBlock">
                <Setter Property="Foreground" Value="DarkRed"/>
                <Setter Property="FontFamily" Value="Segoe UI Semilight"/>
                <Setter Property="FontSize" Value="15"/>
            </Style>
            <Style x:Key="StatusStyle" TargetType="TextBlock">
                <Setter Property="Foreground" Value="Black"/>
                <Setter Property="FontFamily" Value="Segoe UI Semilight"/>
                <Setter Property="FontSize" Value="15"/>
            </Style>
            <ResourceDictionary.MergedDictionaries>
                <!-- 
                    Styles that define common aspects of the platform look and feel
                 -->
                <ResourceDictionary Source="Common/Styles1.xaml"/>
                <ResourceDictionary Source="Common/Styles2.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

For info on how merged dictionary resources are resolved, see the "Merged resource dictionaries" section of ResourceDictionary and XAML resource references.

The x:Key property

In XAML, the keys for ResourceDictionary items are declared by setting the x:Key attributeon elements that represent the XAML resources. Typically, if you try to put a child element that does not have a key value into a ResourceDictionary, this throws a XAML parse exception or a Windows Runtimeexception. The exception condition might also be noted as a warning by XAML design surfaces. However, there are three notable cases where a ResourceDictionary child element won't require an x:Key attributevalue:

Iterating through a ResourceDictionary

You can iterate through a ResourceDictionary in C# or Microsoft Visual Basic. In many cases, such as using foreach syntax, the compiler does this casting for you and you won't need to cast to IEnumerable explicitly. If you do need to cast explicitly, for example if you want to call GetEnumerator, cast to IEnumerable<T> with a KeyValuePair<Object,Object> constraint.

ResourceDictionary and Microsoft Visual Studio

Microsoft Visual Studio provides an Add New Item page choice for a resource dictionary. Use this option whenever you want to define a new loose XAML resource dictionary, for example to serve as the source for a merged dictionary. Microsoft Visual Studio also adds a loose XAML resource dictionary to the project whenever you use Add New Item to create a templated control. This resource dictionary provides the default theme templates. Microsoft Visual Studio might create a new ResourceDictionary for you in your XAML if you are editing copies of styles or templates and a ResourceDictionary for your chosen resource location (app, page, or standalone) doesn't exist yet.

Notes on XAML syntax

Notice that the XAML implicit collection syntax for ResourceDictionary does not include an object element for the ResourceDictionary. This is an example of XAML implicit collection syntax; a tag representing the collection element can be omitted. The elements that are added as items to the collection are specified as child elements of a property element of a property whose underlying type supports a dictionary / map Add method.

For a merged resource dictionary, you do need to explicitly declare a ResourceDictionary object element, so that you can also declare the MergedDictionaries property element and Source. Thus there are a minimum of two ResourceDictionary object elements involved, and you use this syntax.

<ResourceDictionary>
  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="uri"/>
    ...
  </ResourceDictionary.MergedDictionaries>
...
</ResourceDictionary>

In this syntax the outer ResourceDictionary is the primary ResourceDictionary. The inner ResourceDictionary is the ResourceDictionary being merged.

For the implicit collection usage, the placeholder as appropriate for the property Resources is shown. You could also use this implicit collection usage for the Resources property, or potentially for a custom property that uses ResourceDictionary as its property type.

Shareable types and UIElement types

A resource dictionary is a technique for defining shareable types and values of these types in XAML. Not all types or values are suitable for usage from a ResourceDictionary. Examples of types where sharing is supported include Style, any FrameworkTemplate subclass, the XAML intrinsic data types, brushes, colors, and transforms. For more info on which types are considered shareable, see ResourceDictionary and XAML resource references. Generally, UIElement -derived types are not shareable unless they come from templates and application of a template on a specific control instance. Excluding the template case, a UIElement is expected to exist in only one place in an object tree after it is instantiated, and having a UIElement be shareable would potentially violate this principle.

In practice, the vast majority of the resources defined in a ResourceDictionary will be one of these:

  • Control templates for a control, including its visual states.
  • Supporting styles for parts of controls
  • Styles for elements that are part of typical app UI but aren't controls, like TextBlock
  • Data templates for controls and panels that use data binding
  • Specific Brush values, mostly SolidColorBrush
  • Strings or other constants that never need to be localized (strings and constants that do need to be localized shouldn't be in a ResourceDictionary; for more info see Quickstart: Translating UI resources)

Accessing a ResourceDictionary object in code

The API that your code uses to access the resources in a ResourceDictionary depends on which programming language you use:

For more info on how to use ResourceDictionary in code, see "Using a ResourceDictionary from code" section of ResourceDictionary and XAML resource references.

System resources

Some theme resources reference system resource values as an underlying sub-value. A system resource is a special resource value that isn't found in any XAML resource dictionary. These values rely on behavior in Windows Runtime XAML support to forward values from the system itself, and represent them in a form that a XAML resource can reference.

Resource loading optimization in Windows 8.1

Starting with Windows 8.1, there's a resource loading optimization that's enabled by the app model and the Windows Runtime XAML parser. For Windows 8, the XAML parser loaded resources from app.xaml and created each of them as objects as part of startup. That wasn't very efficient if there were big dictionaries there. Also, those resources included the items that were needed by all three themes, and two of the three themes wouldn't even be active. Starting with Windows 8.1, the XAML parser only creates the resources when they're specifically requested. The request might come from other resources or from app or page XAML as each is loaded. This parser behavior minimizes the time it takes to read the app-level dictionary at startup time, and enables the first app page to load faster in most cases. Resources needed by other currently inactive themes are only loaded if that theme is chosen to become the active theme by the user. At that time, any resource where the {ThemeResource} markup extension was used for the request is recalculated based on the newly active theme.

Windows 8 behavior

Windows 8 didn't have the optimizations described above. The ResourceDictionary for Application.Resources had to finish parsing before any page other than the splash screen could load into the app's Window. Because of this you might see some differences in timing when you retarget your app for Windows 8.1. The app should be loading faster, however it may not be possible to isolate this improvement versus other changes you've made to your app code as part of retargeting. Some of the places where you might see evidence of timing changes due to optimized resource loading include when the constructors are called by the parser, for objects like Application objects, converters, or other custom classes. Apps that were compiled for Windows 8 but running on Windows 8.1 continue to use the Windows 8 behavior.

For more info on performance and XAML resource factoring, see Optimize your XAML markup.

Constructors summary

Initializes a new instance of the ResourceDictionary class.

Properties summary

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

Gets the number of elements contained in the collection.

Gets or sets a Uniform Resource Identifier (URI) that provides the source location of a merged resource dictionary.

Gets a collection of merged resource dictionaries that are specifically keyed and composed to address theme scenarios, for example supplying theme values for "HighContrast".

Methods summary

Removes all items from this ResourceDictionary.

Returns an iterator for the items in the collection.

Retrieves a view against the ResourceDictionary.

Returns whether the ResourceDictionary has an entry with the requested key.

Adds a new entry to the ResourceDictionary.

Returns the value from the requested key, if an entry with that key exists.

Removes a specific item from the ResourceDictionary.

Constructors

  • ResourceDictionary()
    ResourceDictionary()
    ResourceDictionary()
    ResourceDictionary()

    Initializes a new instance of the ResourceDictionary class.

    public ResourceDictionary()public ResourceDictionary()Public Function ResourceDictionary() As

Properties

  • MergedDictionaries
    MergedDictionaries
    MergedDictionaries
    MergedDictionaries

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

    public IVector<ResourceDictionary> MergedDictionaries { get; }public IVector<ResourceDictionary> MergedDictionaries { get; }Public ReadOnly Property MergedDictionaries As IVector<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.

    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 Resources or 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 Resources or Resources collections that can reference resources by key, including the merged resources.

    Examples

    The starting Microsoft Visual Studio templates for a Windows Store 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>
    
  • Size
    Size
    Size
    Size

    Gets the number of elements contained in the collection.

    public uint Size { get; }public uint Size { get; }Public ReadOnly Property Size As uint

    Property Value

    • uint
      uint
      uint

      The number of elements contained in the collection.

    Remarks

    Note

    The equivalent Microsoft .NET API is Count.

  • Source
    Source
    Source
    Source

    Gets or sets a Uniform Resource Identifier (URI) that provides the source location of a merged resource dictionary.

    public Uri Source { get; set; }public Uri Source { get; set; }Public ReadWrite Property Source As Uri
    <ResourceDictionary Source="uri"/>
    

    Property Value

    • A Uniform Resource Identifier (URI) that provides the source location of a merged resource dictionary. This is typically a path that references a XAML resource within the app, or a reference to a loose XAML file.

  • ThemeDictionaries
    ThemeDictionaries
    ThemeDictionaries
    ThemeDictionaries

    Gets a collection of merged resource dictionaries that are specifically keyed and composed to address theme scenarios, for example supplying theme values for "HighContrast".

    public IMap<object, object> ThemeDictionaries { get; }public IMap<object, object> ThemeDictionaries { get; }Public ReadOnly Property ThemeDictionaries As IMap<object, object>
    <ResourceDictionary>
      <ResourceDictionary.ThemeDictionaries>
        oneOrMoreThemeDictionaries
      </ResourceDictionary.ThemeDictionaries>
    </ResourceDictionary>
    

    Property Value

    Remarks

    Theme dictionaries have two primary scenarios: resources for your own app, and resources that the system provides for you on a per-theme basis. You'll only need to set values for the ThemeDictionaries resource set if you're defining your own app resources in app.xaml. Otherwise, the {ThemeResource} markup extension usages you'll be using in XAML control templates and elsewhere are typically referring to the system ThemeDictionaries resources, which can be viewed for design purposes within the generic.xaml design file.

    Brush resources are often theme-specific. Default Windows Runtime XAML control UI defines many brush resources that are used for the various default XAML controls. You can see these resource definitions as part of the generic.xaml design file. The system ThemeDictionaries definitions are located early in the file, so that they are lexically forward of the {ThemeResource} markup extension s that reference them from within the default control templates. Your own page definitions and custom control definitions can make {ThemeResource} markup extension references to the system-supplied theme resources. In fact that's a recommended practice if you are writing controls that are intended to be in the same UI as the default controls. The default controls are using the theme resources extensively, and using the theme resources in your own controls can help prevent visual mismatches if the user changes the theme at runtime, or if the app is running under a theme that you hadn't specifically designed for.

    There are also non-brush resources in the system theme resources in generic.xaml, such as default measures and font properties.

    Theme dictionaries that you specify for individual apps aren't intended to supply the resource definition of an entire app theme. Instead, you should factor your page UI and custom control definitions to use system theme resources whenever possible, and to use app-specific theme resources for just a few cases where you want to override the system default values. For page-level app UI you typically only need new theme resources for certain non-brush resources used in composition such as glyphs or path-based graphics. The resources in ThemeDictionaries that you define yourself are intended for scenarios like accessibility. In particular, different resources might be needed for high contrast themes. For more info on the high contrast scenario, see High-contrast themes. For more info on system-supplied themes, see RequestedTheme or XAML requested theme sample.

    The expected keys for the basic themes are "Light" and "Dark".

    For custom controls, you should also have a "HighContrast" keyed theme dictionary whenever you have theme dictionaries for "Light" and "Dark". There are other named high contrast themes, but the "HighContrast" theme key is the fallback the system uses for finding the high contrast theme if no other theme resources for high contrast are available.

    For custom controls, if you don't support "Light" and "Dark" themes and only support one theme as well as at least one "HighContrast" theme, you can change your main dictionary's x:Key attribute to "Default". "Default" is the ResourceDictionary that will be used if a ResourceDictionary in the specified theme (such as "Dark") cannot be found.

    For high contrast themes and custom control scenarios, in addition to system brush resources, there are also system color resources such as "SystemColorButtonFaceColor" that you can assign to be the Color value of SolidColorBrush resources. You can use these as values for your "HighContrast" theme dictionary and also "Default". If the resource exists for each of the themes your control supports, the XAML templates will load the appropriate resource for the theme that's active.

    Examples

    This example shows a ThemeDictionaries dictionary that defines brush styles for a "Default" theme, two existing "HighContrast*" themes that map to user theme choices for high contrast, and a custom high contrast theme. The dictionary is used by a control template for a custom control. This is part of the High contrast sample.

    <ResourceDictionary>
      <ResourceDictionary.ThemeDictionaries> 
        <ResourceDictionary x:Key="Default"> 
          <SolidColorBrush x:Key="TargetBackground" Color="Red"/> 
          <SolidColorBrush x:Key="TargetBorderBrush" Color="Black"/> 
          <SolidColorBrush x:Key="Circle4Fill" Color="Blue"/> 
          <SolidColorBrush x:Key="Circle3Fill" Color="Green"/> 
          <SolidColorBrush x:Key="Circle2Fill" Color="Yellow"/> 
          <SolidColorBrush x:Key="Circle1Fill" Color="White"/> 
          <SolidColorBrush x:Key="CircleStroke" Color="Black"/> 
        </ResourceDictionary> 
        <ResourceDictionary x:Key="HighContrastBlack"> 
           <SolidColorBrush x:Key="TargetBackground" Color="Black"/> 
           <SolidColorBrush x:Key="TargetBorderBrush" Color="White"/> 
           <SolidColorBrush x:Key="Circle4Fill" Color="Black"/> 
           <SolidColorBrush x:Key="Circle3Fill" Color="Black"/> 
           <SolidColorBrush x:Key="Circle2Fill" Color="Black"/> 
           <SolidColorBrush x:Key="Circle1Fill" Color="Black"/> 
           <SolidColorBrush x:Key="CircleStroke" Color="White"/> 
         </ResourceDictionary> 
         <ResourceDictionary x:Key="HighContrastWhite"> 
           <SolidColorBrush x:Key="TargetBackground" Color="White"/> 
           <SolidColorBrush x:Key="TargetBorderBrush" Color="Black"/> 
           <SolidColorBrush x:Key="Circle4Fill" Color="White"/> 
           <SolidColorBrush x:Key="Circle3Fill" Color="White"/> 
           <SolidColorBrush x:Key="Circle2Fill" Color="White"/> 
           <SolidColorBrush x:Key="Circle1Fill" Color="White"/> 
           <SolidColorBrush x:Key="CircleStroke" Color="Black"/> 
        </ResourceDictionary> 
        <ResourceDictionary x:Key="HighContrastCustom"> 
          <SolidColorBrush x:Key="TargetBackground" Color="{StaticResource SystemColorButtonFaceColor}"/> 
          <SolidColorBrush x:Key="TargetBorderBrush" Color="{StaticResource SystemColorButtonTextColor}"/> 
          <SolidColorBrush x:Key="Circle4Fill" Color="{StaticResource SystemColorHotlightColor}"/> 
          <SolidColorBrush x:Key="Circle3Fill" Color="{StaticResource SystemColorHotlightColor}"/> 
          <SolidColorBrush x:Key="Circle2Fill" Color="{StaticResource SystemColorHotlightColor}"/> 
          <SolidColorBrush x:Key="Circle1Fill" Color="{StaticResource SystemColorHotlightColor}"/> 
          <SolidColorBrush x:Key="CircleStroke" Color="{StaticResource SystemColorHighlightTextColor}"/> 
        </ResourceDictionary> 
      </ResourceDictionary.ThemeDictionaries>
    </ResourceDictionary>
    

    The starting Microsoft Visual Studio templates for a Windows Store app using C++, C#, or Visual Basic include a ThemeDictionaries node in the XAML file that is the starting MergedDictionaries value for an app.xaml file. All the built-in Windows Runtime controls already have high-contrast themes defined elsewhere (the native equivalent of generic.xaml) or use system theme resources so they can respond to themes, so the starting content of an app-specific ThemeDictionaries resource set is minimal. It's only once you start defining custom controls or app-specific theme styles that you'll see more resource definitions here.

    <ResourceDictionary
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    
        <!-- Non-brush values that vary across themes -->
    
        <ResourceDictionary.ThemeDictionaries>
            <ResourceDictionary x:Key="Default">
                <x:String x:Key="BackButtonGlyph">&#xE071;</x:String>
                <x:String x:Key="BackButtonSnappedGlyph">&#xE0BA;</x:String>
            </ResourceDictionary>
    
            <ResourceDictionary x:Key="HighContrast">
                <x:String x:Key="BackButtonGlyph">&#xE0A6;</x:String>
                <x:String x:Key="BackButtonSnappedGlyph">&#xE0C4;</x:String>
            </ResourceDictionary>
        </ResourceDictionary.ThemeDictionaries>
    ...
    </ResourceDictionary>
    

Methods

  • Clear()
    Clear()
    Clear()
    Clear()

    Removes all items from this ResourceDictionary.

    public void Clear()public void Clear()Public Function Clear() As void
  • First()
    First()
    First()
    First()

    Returns an iterator for the items in the collection.

    public IIterator<IKeyValuePair<object, object>> First()public IIterator<IKeyValuePair<object, object>> First()Public Function First() As IIterator( Of IKeyValuePairobject, object )

    Returns

    • The iterator. The iterator's current position is at the 0-index position, or at the collection end if the collection is empty.

    Remarks

    You can iterate through a ResourceDictionary in C# or Microsoft Visual Basic. In many cases, such as using foreach syntax, the compiler does this casting for you and you won't need to cast to IEnumerable<KeyValuePair> explicitly. If you do need to cast explicitly, for example if you want to call GetEnumerator, cast to IEnumerable<T> with a KeyValuePair<Object,Object> constraint.

  • GetView()
    GetView()
    GetView()
    GetView()

    Retrieves a view against the ResourceDictionary.

    public IMapView<object, object> GetView()public IMapView<object, object> GetView()Public Function GetView() As IMapView( Of object, object )

    Returns

    • The view object.

    Remarks

    Note

    There is no exact Microsoft .NET equivalent for this API, although CopyTo is similar.

  • HasKey(System.Object)
    HasKey(System.Object)
    HasKey(System.Object)
    HasKey(System.Object)

    Returns whether the ResourceDictionary has an entry with the requested key.

    public bool HasKey(System.Object key)public bool HasKey(System.Object key)Public Function HasKey(key As System.Object) As bool

    Parameters

    • key
      System.Object
      System.Object
      System.Object

      The requested key.

    Returns

    • bool
      bool
      bool

      true if the ResourceDictionary has an entry with the requested key; otherwise, false.

    Remarks

    Note

    The equivalent Microsoft .NETAPI is ContainsKey.

  • Insert(System.Object,System.Object)
    Insert(System.Object,System.Object)
    Insert(System.Object,System.Object)
    Insert(System.Object,System.Object)

    Adds a new entry to the ResourceDictionary.

    public bool Insert(System.Object key,System.Object value)public bool Insert(System.Object key,System.Object value)Public Function Insert(key As System.Object,value As System.Object) As bool

    Parameters

    • key
      System.Object
      System.Object
      System.Object

      The object key for the resource to insert.

    • value
      System.Object
      System.Object
      System.Object

      The object value for the resource to insert.

    Returns

    • bool
      bool
      bool

      true if calling the method replaced a value that already existed for the key; false if calling the method defined a new key.

    Remarks

    Note

    The equivalent Microsoft .NET API is Add.

  • Lookup(System.Object)
    Lookup(System.Object)
    Lookup(System.Object)
    Lookup(System.Object)

    Returns the value from the requested key, if an entry with that key exists.

    public object Lookup(System.Object key)public object Lookup(System.Object key)Public Function Lookup(key As System.Object) As object

    Parameters

    • key
      System.Object
      System.Object
      System.Object

      The requested key.

    Returns

    • object
      object
      object

      The value, if an item with the specified key exists. Use the HasKey method to determine whether the key exists.

    Remarks

    Note

    The equivalent Microsoft .NET API is the Item indexer.

  • Remove(System.Object)
    Remove(System.Object)
    Remove(System.Object)
    Remove(System.Object)

    Removes a specific item from the ResourceDictionary.

    public void Remove(System.Object key)public void Remove(System.Object key)Public Function Remove(key As System.Object) As void

    Parameters

    • key
      System.Object
      System.Object
      System.Object

      The key of the item to remove.

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ComposableAttribute
Windows.Foundation.Metadata.ThreadingAttribute
Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.WebHostHiddenAttribute

Details

Assembly

Windows.UI.Xaml.dll