Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Silverlight
Silverlight 2
 Resources Property

  Switch on low bandwidth view
This page is specific to
Microsoft Silverlight 2

Other versions are also available for the following:
.NET Framework Class Library for Silverlight
FrameworkElement..::.Resources Property

Gets the locally defined resource dictionary. In XAML, you can establish resource items as child object elements of the <object.Resources> property element, through XAML implicit collection syntax.

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

value = instance.Resources
C#
public ResourceDictionary Resources { get; }
XAML Property Element Usage
<object>
  <object.Resources>
    oneOrMoreResourceElements
  </object.Resources>
</object>

XAML Values

oneOrMoreResourceElements

One or more object elements, each of which creates and defines a resource. Each resource property element within a ResourceDictionary must have a unique key, specified as an attribute. The key is used when values are retrieved from the ResourceDictionary.

Property Value

Type: System.Windows..::.ResourceDictionary
The current locally defined dictionary of resources, where each resource can be accessed by its key.

Resource dictionaries that can be defined completely or partially in XAML are typically created through a XAML property element for the Resources property, and are typically on the root for any individual page in an application or for the application object. Placing the resource dictionary at this level makes it easier to reference resources in scope from individual child objects in the object tree defined in a XAML page.

Resources created from a XAML-defined resource dictionary can be referenced by code by calling the ResourceDictionary API after you get the value for Resources, but be aware that resources created in XAML will definitely not be accessible until after Loaded is raised by the object that declares the dictionary.

The underlying ResourceDictionary type of the property's value supports the members that are required to add, remove or query resources from within the dictionary by using code.

Notice that the XAML syntax shown does not include an object element for the ResourceDictionary class. 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 collection Add method.

If you intend to use resources from XAML markup, you should map the XML namespace for XAML through an xmlns declaration. This is necessary because resources defined in markup must each have a unique key value. Key is defined in the XAML namespace, and Key is generally the way to specify a resource key for Silverlight, except for in some special scenarios. Mapping the XML namespace for XAML is already done for you by most (if not all) tools that produce XAML for Silverlight.

NoteNote:

The Silverlight documentation assumes the typical mapping prefix of x: for the XAML namespace, therefore references to "Key" in the documentation are typically in the form x:Key, with the x prefix. Also, it is typical to map both the default Silverlight namespace and the XAML namespace (to x: prefix) at the root level.

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

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker