Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
How to: Extract a WPF Resource

How to: Extract a WPF Resource

Visual Studio 2010

When you create a Brush for an element, you enhance its reusability by factoring it into a ResourceDictionary. Use the Properties window to extract resources into reusable XAML.

To extract a WPF resource

  1. From the Toolbox, drag a TextBlock control onto the Window.

  2. Create a brush for the Background property. For more information, see How to: Create a Brush by Using the Brush Editor.

  3. At the top of the Properties window, click the Alphabetical button.

  4. Scroll to the Background property.

  5. At the edge of the left column, click the Local property marker local (property marker local).

    A menu appears.


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

  6. Click Extract Value to Resource.

    The Create Resource dialog box appears.

    Create Resource dialog box
  7. In the Key text box, type BackgroundBrush.

  8. Click OK.

    A resource named BackgroundBrush is added to the parent control's resource dictionary, and the StaticResource markup extension is assigned to the TextBlock control's Background property.

  9. In XAML view, find the BackgroundBrush resource.

Community Additions

© 2015 Microsoft