2. Brushes
Another common task in Blend is to select how to “paint” a particular element of your design.XAML uses brushes to paint surfaces, and Blend supports this through
the Brushes section of the Properties panel, as shown in Figure 9.
Figure 9. Brushes in the Properties panel
The Brushes section of the Properties panel is made up of a number of
sections you will want to become familiar with. The first section (#1
in Figure 8) lists the brushes the particular object supports. In this example it’s a simple Rectangle
object, so you can set the brush for both the Fill
and the Stroke
of the Rectangle
. This is like a small ListBox
,
so picking a brush will let you pick the properties for that brush in
the lower part of the Brushes section. The second section (#2) lists the
available brush types. This section takes the form of a set of tabs for
each type of brush. Table 1 lists the brush editors.
Table 1. Brush Editors
Within the brush editor you can directly create two types of
resources: color resources and brush resources. These are created in
different ways, but both originate on the brush editor. First, let’s
create a color resource. We can do this by clicking the small square
next to the color picker, as shown in Figure 10.
Figure 10. Converting a color to a resource
Selecting Convert to New Resource opens a dialog box where you can
create a new named resource that will show up in the Resources list in
the color editor, as shown in Figure 11.
Figure 11. Creating a color resource
After you name the resource, you will also need to specify where to
define the resource. Your options are labeled “Application,” “This
document,” and “Resource dictionary.” Typically you would choose
“Application” or “Resource dictionary” if you have one. Defining a
resource at the application level allows the resource to be used on any
page in your application. Defining this resource enables you to specify
it by name, and if it’s changed later in the design workflow, the change
affects every use of this color. This color resource can also be used
in other brushes (for example, gradient brushes). Once you have a color
resource, you can use it via the “Color resources” tab, as shown in Figure 12.
Figure 12. Applying a color resource
The other type of resource is a brush resource. This is different
because, instead of defining a color to be used in a brush, you can
define an entire brush (for example, image, gradient, or solid color
brush). This way, you can define a named brush so that if you later
change a brush from a solid color brush to a gradient brush the change
cascades to all uses. You can create a brush resource like you created a
color resource, but the context menu is in a different location. This
time you will use the small square to open the context menu on the brush
itself instead of the color, as shown in Figure 13.
Figure 13. Creating a brush resource
Applying the brush resource is similar, too. You would show the
Resource Brush tab and pick the local brush resource you want to use, as
shown in Figure 14.
Figure 14. Applying a brush resource
Dealing with brushes is a pretty typical task. Using these
techniques, you’ll be up to speed in using Blend to create your Windows
Phone applications quickly.