笔刷可以通过填充颜色,已有图像使控件出现一种特种效果,从而达到一种意想不到的效果。
常用笔刷有以下几种:
<SolidColorBursh></SolidColorBrush>实体笔刷,以一种颜色填充空间。
<ImageBrush></ImageBrush>图像笔刷,以图像填充控件。
<ImageBrush>重要属性如下:
ImageSource:设置笔刷图像源路径,Stretch:设置图像重叠方式,ViewBox:设置图像显示位置,TileMode设置重叠方式。
代码如下:
<Grid>
<Ellipse Height="57" HorizontalAlignment="Left" Margin="12,242,0,0" Name="ellipse1" Stroke="Black" VerticalAlignment="Top" Width="101" >
<Ellipse.Fill>
<ImageBrush ImageSource="images/1.jpg"></ImageBrush>
</Ellipse.Fill>
</Ellipse>
<Ellipse Height="57" HorizontalAlignment="Left" Margin="119,242,0,0" Name="ellipse2" Stroke="Black" VerticalAlignment="Top" Width="104" >
<Ellipse.Fill>
<ImageBrush ImageSource="images/1.jpg" Stretch="None"/>
</Ellipse.Fill>
</Ellipse>
<Ellipse Height="49" HorizontalAlignment="Left" Margin="242,242,0,0" Name="ellipse3" Stroke="Black" VerticalAlignment="Top" Width="99" >
<Ellipse.Fill>
<ImageBrush ImageSource="images/1.jpg" Viewbox="0,0,0.5,0.5"/>
</Ellipse.Fill>
</Ellipse>
<Ellipse Height="56" HorizontalAlignment="Left" Margin="347,235,0,0" Name="ellipse4" Stroke="Black" VerticalAlignment="Top" Width="108" >
<Ellipse.Fill>
<ImageBrush ImageSource="images/2.bmp" Viewbox="0,0,0.3,0.5" TileMode="FlipX"/>
</Ellipse.Fill>
</Ellipse>
<TextBox Height="23" HorizontalAlignment="Left" Margin="24,25,0,0" Name="txtInput" FontFamily="Arial Black" VerticalAlignment="Top" Width="140" >
<TextBox.Foreground>
<ImageBrush ImageSource="images/1.jpg"/>
</TextBox.Foreground>
<TextBox.Background>
<ImageBrush ImageSource="images/2.bmp"/>
</TextBox.Background>
</TextBox>
<TextBlock Height="43" HorizontalAlignment="Left" Margin="32,75,0,0" Name="textBlock1" FontSize="24" Text="Hello WPF" VerticalAlignment="Top" Width="132">
<TextBlock.Foreground>
<ImageBrush ImageSource="images/1.jpg"/>
</TextBlock.Foreground>
</TextBlock>
</Grid>
本文来自圣兽的博客,原文地址:http://blog.sina.com.cn/s/blog_685269a50100qtm7.html