Compartilhar via


Resources overview

This page applies to WPF and Silverlight 2

A resource is an object that can be reused in different places in your Microsoft Expression Blend application.

The most common use of a resource is in reusing a color throughout your application. For example, you can change a color resource in one place to automatically update the appearance of every control that refers to that color resource. This concept also applies to reusing style or template resources to make controls of a specific type look or behave the same way. Changing one asset that has multiple relationships is easier than changing many instances of data throughout your application.

Virtually everything can be converted to some kind of a resource. For instance:

  • A gradient, solid color, or tile brush can be converted to a brush resource and then applied as a brush to other objects. For an example, see Create a brush or color resource.

  • An image control can be converted to an image brush, drawing brush, or visual brush resource and then applied as a brush to other objects. Use the conversion tools are available under Make Brush Resource on the Tools menu.

  • Any panel or other control on the artboard can be converted to a drawing brush or visual brush resource and then applied as a brush to other objects. Use the conversion tools are available under Make Brush Resource on the Tools menu.

  • A property value in the Properties panel can be converted to a resource value and then applied to properties of the same type. For an example, see Create a resource.

  • A style or control template can be converted to a resource and then applied to a control of the same type (for example, a button template can be applied to other buttons). For more information, see Styles and templates. For examples, see Create a style resource and Create or edit a control template.

    Note

    Style and control template resources can be selected from the Asset Library and then drawn on the artboard—just like system controls. For more information about the controls in the AssetLibrary, see Controls overview.

Resources can be created at various levels or scopes in your application. The scope where a resource is defined determines where it is available in your application. You can define resources at the following scopes:

  • An object-level resource can only be applied to the object that was used to create the resource, or to its child objects.

  • A document-level resource is defined in the document where it was created and can only be applied to objects in the same document.

  • An application-level resource is defined in the App.xaml file and can be applied anywhere within your application.

  • A dictionary-level resource is defined in a separate file called a resource dictionary. Resources in a resource dictionary can be applied anywhere within your application because resource dictionaries are linked to your project in the App.xaml file. An additional benefit of using resource dictionaries is that you can package a set of resources into a resource dictionary file and reuse the entire file in another application.

    Note

    Resource dictionaries are not supported in Silverlight 2.

    Note

    Expression Blend comes with a resource dictionary that contains a set of style and template resources for common system controls. These simple controls are available from the Simple Styles section in the Controls tab of the Asset Library. For more information, see Working with simple styles. For specific examples, see the topics listed under Try it! in Simple styles.

    Note

    Microsoft Expression Design 2 uses resource dictionaries to export art assets that can be imported into an Expression Blend application and accessed from the Resources panel. For an example, see Import XAML that is exported from Expression Design.

Existing resources can be moved between different scopes by dragging them between locations in the Resources panel. Additionally, you can access an existing resource for editing from the Resources panel. For information about editing resources, see Modify a resource. For a roadmap of the Resources panel, see the Resources panel.

For information about applying a resource to an object on the artboard, see Apply or remove a resource. When applying a resource that is a style or control template, you can use the additional method that is described in Apply a style resource.