Chapter 8


After completing this chapter, you will be able to:

  • Create color resources and use them in Microsoft Expression Blend applications.
  • Create and apply gradient and image brushes.
  • Convert property values to resource values and apply them to properties of the same type.
  • Modify existing resources.
  • Organize resources by using dictionaries.
Expression Blend increases your productivity and improves the performance of your applications by allowing the use of resources. A resource is an object that you or others can reuse in different places in your Expression Blend projects. Most often, reusable resources are colors or brushes that are applied to other objects. A brush can be based on a gradient, an image, or even a video. Beyond basic resources you can reuse margins, font sizes, corner radii, alignments, and more. The concept of resources goes beyond individual properties and can include complex resources such as styles and templates (see Chapter 9, "Skinning Controls”) that allow you to make controls of the same type (such as buttons) look similar and behave the same way. Instead of copying and pasting the objects or attributes multiple times , you can store, use, and change resources in one location, editing them directly in XAML files or working visually through the Resource panel, which lists all the resources used in your current project. Expression Blend also gives you a flexible way to organize resources by using resource dictionaries.

Color Resources

Consistent colors are important in an application. Storing colors as reusable color resources makes it easy to apply specific colors to objects throughout your application. When you use a consistent color palette in an application’s elements, controls, and screens, it looks more professional and complete.

Create Color Resource Dialog Box

Image Brush Resources

Brush resources aren’t limited to just solid colors or gradients. It’s also possible to use images as brush resources. If there are a lot of places in your document or application where you might want to use the same image, but stretched or skewed in different ways, it’s better to create an image brush resource and use it for fill, stroke, or even as an opacity mask .

Create Image Brush Resource

Modifying Resources

The main advantage of using resources is that you can modify them in a centralized place. You don’t need to change the value of font sizes twice for different text objects if they both use the same resource; you can modify the value once, from the Resource panel.

Expression Blend Resources Panel

Working with External Resource Dictionaries

As mentioned earlier in this chapter, there are four available levels for storing resources: the application level, the document level, the object level, and the external resource dictionary level. So far you have used only one level—application level . You can also choose to store your resources in a resource dictionary, which is a separate file that you can reuse in other projects. Resource dictionaries are linked to your project by dictionary references in the App.xaml file or by reference in another resource dictionary file.

Create New Resource Dictionary Dialog Box

You can easily make this a point to YOUR company OR hide it all together.