Exercise 3: Creating and Using Resources
- For this exercise, you can continue to use the solution from Exercise 2 or open the begin solution located at\Ex03-CreatedAndUsingResources\begin\(Choosing the folder that matches the language of your preference.) You will need to build the solution (click Build | Build Solution) before the designer will show the WPF work we did in Exercise 2.
- Open Window1.xaml and select the forwardButton created in Exercise 2.
In the Properties window, use the Search tool to find the Background property.
Figure 19
Setting Background Property
- Click the Background property and the Brush editor will appear. Click the eyedropper tool and select a color from anywhere on your screen. You will see the background of the button has changed.
Now click the black square next to background label in the property browser to pick the “Extract to Resource” option.
Figure 20
Extract Value to Resource
- Click OK in the Create Resource dialogue, accepting the default values. This window lets you extract the property’s value into a resource that you can re-use. In this case, the resource will be created in Window1.xaml.
Look in the XAML code editor and you’ll find a SolidColorBrush element inside the Window.Resources node.
<Window.Resources> <!-- Additional Resources Omitted --> <SolidColorBrush x:Key="LightOrangeBrushKey">#FFFFF0D0</SolidColorBrush> </Window.Resources>
- Select the backButton and locate the Background property in the properties windows.
Click the black square in the properties window next to the Background property label and select Apply Resource.
Select the resource from the Local expander.
- The forwardButton and backButton now share the same resource, defining the Background.
Next Step
Summary
|
|