How to: Create a New WPF Resource
[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
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
In the WPF Designer, select a control that has a Background property.
In the Properties window, click the Alphabetical button, and then scroll to the Background property.
In the Value column, click the down button.
The brush editor appears.
Click the Gradient Brush option, and choose colors for the brush.
Click the Background property to accept the brush and close the brush editor.
In the Background property, at the edge of the left column, click the Local property marker ().
A menu appears.
Tip
You can also right-click the row to display the menu.
Click Extract Value to Resource.
The Create Resource dialog box appears.
In the Key field, type the name of the new brush resource.
In the Destination field, select the XAML file that will contain the new brush resource.
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 ().
To create an image resource
From the Toolbox, drag an Image control onto the design surface.
In the Properties window, scroll to the Source property.
In the Value column, click the ellipsis button (...).
The Choose image dialog box appears.
Select an image or click the Add button to add an image.
Click OK.
The image appears in the Image control.
Follow steps 6 through 10 in the previous procedure for the Source property.
See Also
Tasks
How to: Embed an Icon in an Assembly