Silverlight图形 - 画笔2010-12-10 MSDN 使用纯色绘制区域在任何平台上,最常见的一个操作就是使用纯色绘制区域。 为了实现此任务 ,Silverlight 提供了 SolidColorBrush 类。 以下各节介绍使用 SolidColorBrush 进行绘制的不同方式。若要在 XAML 中用纯色绘制区域,请使用以下选项之一:按名称选择一个预定义的 SolidColorBrush。 例如,可以将 Rectangle 的 Fill 设置为"Red"或"MediumBlue"。 该示例使用预定义 SolidColorBrush 的名 称来设置 Rectangle 的 Fill。XAML<StackPanel> <!-- This rectangle"s fill is painted with a red SolidColorBrush, described using a named color. --> <Rectangle Width="100" Height="100" Fill="Red" /> </StackPanel>通过指定红色、绿色和蓝色的分量以组合成单一纯色,从 32 位调色板中选 择一种颜色。 从 32 位调色板中指定一种颜色时使用的格式为 #rrggbb,其中 rr 是指定红色相对量的两位十六进制数,gg 指定绿色相对量,bb 指定蓝色相 对量。 此外,还可以按 #aarrggbb 格式指定颜色,其中 aa 指定颜色的 alpha 值或透明度。 通过此方法可以创建部分透明的颜色。 在下面的示例中,使用十 六进制表示法将 Rectangle 的 Fill 设置为完全不透明的红色。XAML<StackPanel> <!-- This rectangle"s background is painted with a red SolidColorBrush, described using hexadecimal notation. --> <Rectangle Width="100" Height="100" Fill="#FFFF0000" /> </StackPanel>使用属性元素语法描述 SolidColorBrush。 此语法更为详细,可用于指定其 他设置,如画笔的不透明度。 在下面的示例中,两个 Rectangle 元素的 Fill 属性设置为完全不透明的红色。 第一支画笔的颜色使用预定义的颜色名称进行 描述。 第二支画笔的颜色使用十六进制表示法进行描述。XAML<StackPanel>
<!-- Both of these rectangles" fills are painted with red SolidColorBrush objects, described using object element syntax. --> <Rectangle Width="100" Height="100"> <Rectangle.Fill> <SolidColorBrush Color="Red" /> </Rectangle.Fill> </Rectangle>