Create and apply reusable assets

This page applies to WPF projects only

You can reuse a brush or other property value by converting it to a resource and applying it to another property. This is useful if you want to create and reuse a set of colors or other values that will define the unique look of your application.

To create and apply reusable assets

  1. Click the Selection Cc296401.2ff91340-477e-4efa-a0f7-af20851e4daa(en-us,Expression.10).png tool, and then on the artboard, hold the CTRL key while you drag your rectangle to create a copy.

    Cc296401.172f9c5d-6de4-4848-ac16-d1081e6604d0(en-us,Expression.10).png

    You can also copy and paste using the usual keyboard shortcuts CTRL+C and CTRL+V, or by using the items on the Edit menu. Notice that the second rectangle appears to be in front of the first. This is because of the stacking order of objects.

  2. With the second rectangle selected, click the Fill property under Brushes in the Properties panel. At the bottom of the Brushes window, click the Convert brush to resource Cc296401.c6247e94-077c-40e1-8979-7886a2eaa8ef(en-us,Expression.10).png button. The Create Brush Resource dialog box appears.

    Cc296401.092a1fec-f5b5-427c-a51e-aae1f6a1eee2(en-us,Expression.10).png

    The Name field is the resource key. The Define in field determines the scope where you want your resource defined. With This document selected, the resource will be available only to objects that are contained in this document. If you select the Application scope, this resource will be available to all the documents in your application, but not to other projects. If you define your brush in a new resource dictionary, you can always add the resource dictionary to other projects so that your brush resource can be used in those projects. It is by defining multiple resources in a single dictionary that you can ensure a common look between applications.

  3. Click the New button. The New Item dialog box appears. You can leave the fields as they are and click OK.

    Cc296401.d4af870c-c1d0-41f8-91e2-9f0e7bb93128(en-us,Expression.10).png

    A new resource dictionary is created and visible in the Project tab. You are returned to the Create Brush Resource dialog box.

  4. Your new resource dictionary is now selected, so click OK to create the new brush resource.

  5. Click the Resources tab, expand the node for your resource dictionary, and then click on the drop-down arrow next to your brush resource. The color editor opens so that you can modify your brush resource. Change the purple gradient stop to yellow.

    Cc296401.ef3e6aac-b32c-44ea-bcb1-8527f9903c26(en-us,Expression.10).png

    Your brush resource can be applied to any brush property of any object.

  6. Select your other rectangle, and then in the Properties panel, click the Advanced property options Cc296401.d6ba8f4a-b8a2-445a-af0b-a267dfade6e1(en-us,Expression.10).png marker beside the Fill property.

    Cc296401.3a34ccd9-9d90-4d53-8555-fca5c6698406(en-us,Expression.10).png

    A drop-down menu appears.

  7. From the drop-down menu, click Local Resource, and then select Brush1. Your brush resource is now applied to both rectangles.

    Cc296401.7c2d7391-44c2-4afd-8acc-838bf7bd5b38(en-us,Expression.10).png

    If you change your brush resource in the Resources panel again, the changes will be reflected on both rectangles.

Next steps

See also

Concepts

Restore the default style

Create or edit a control template

Working with simple styles

Try it: Create a rollover button

Try it: Create a button by using bitmap effects

Create or modify a drawing brush resource