Share via


How to: Create a New WPF Resource

You can easily create resources, such as brushes and images, in your WPF application by using the WPF Designer for Visual Studio. Once created, you can re-use these resources anywhere in your WPF application.

To create a brush resource

  1. In the WPF Designer, select a control that has a Background property.

  2. In the Properties window, click the Alphabetical button, and then scroll to the Background property.

  3. In the Value column, click the down button.

    The brush editor appears.

  4. Click the Gradient Brush option, and choose colors for the brush.

    Brush Editor

  5. Click the Background property to accept the brush and close the brush editor.

  6. In the Background property, at the edge of the left column, click the Local property marker (property marker local).

    A menu appears.

    Tip

    You can also right-click the row to display the menu.

  7. Click Extract Value to Resource.

    The Create Resource dialog box appears.

  8. In the Key field, type the name of the new brush resource.

  9. In the Destination field, select the XAML file that will contain the new brush resource.

    Create Resource dialog box

  10. Click OK to create the brush resource.

    The brush resource is created in the destination XAML file. A static resource markup extension is added to the Background property with the name that you specified (Background="{StaticResource Background1}". Finally, the property marker changes to a brush (Brush Property Marker).

To create an image resource

  1. From the Toolbox, drag an Image control onto the design surface.

  2. In the Properties window, scroll to the Source property.

  3. In the Value column, click the ellipsis button (...).

    The Choose image dialog box appears.

    Choose image dialog box

  4. Select an image or click the Add button to add an image.

  5. Click OK.

    The image appears in the Image control.

  6. Follow steps 6 through 10 in the previous procedure for the Source property.

See Also

Tasks

How to: Embed an Icon in an Assembly

Concepts

Pack URIs in WPF

Other Resources

Resources (WPF)

Using Resources