没事写了点,记性不好容易忘记,方便以后查找,
<Window x:Class="DesktopUI.形状and变换and画刷.画刷"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="画刷" Height="500" Width="900">
<Window.Resources>
<Style TargetType="{x:Type TextBlock}" x:Key="StyTextBlock">
<Style.Setters>
<Setter Property="FontSize" Value="15"/>
</Style.Setters>
</Style>
<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource ResourceKey=StyTextBlock}" x:Key="Desc">
<Setter Property="Margin" Value="5"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="180"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!--VisualBrush画刷-->
<StackPanel Grid.Row="0" Grid.Column="0" Orientation="Vertical">
<TextBlock Text="VisualBrush画刷" Style="{StaticResource ResourceKey=StyTextBlock}"/>
<Rectangle Stroke="Black" Height="150" Width="180">
<Rectangle.Fill>
<VisualBrush>
<VisualBrush.Visual>
<StackPanel Background="White">
<Rectangle Width="25" Height="25" Fill="Red" Margin="2"/>
<TextBlock Text="你好WPF" FontSize="10pt" Margin="2"/>
<Button Margin="2" Content="按钮无法用"/>
</StackPanel>
</VisualBrush.Visual>
</VisualBrush>
</Rectangle.Fill>
</Rectangle>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Vertical">
<TextBlock TextWrapping="Wrap" Style="{StaticResource ResourceKey=Desc}">
Visurl Brush允许开发人员获取一个“元素的内容”来填充图形。比如一个窗体,一个控件都可以用来填充Fill属性,
但填充上去的控件是不可用的,他只是复制,只能当作一个图片来看待....
左边还可以这样写:
</TextBlock>
<Button Name="btn1" Margin="3" Content="复制按钮"/>
<Rectangle Margin="3" Height="60">
<Rectangle.Fill>
<VisualBrush Visual="{Binding ElementName=btn1}"/>
</Rectangle.Fill>
</Rectangle>
</StackPanel>
<!--ImageBrush图像画刷-->
<StackPanel Grid.Row="1" Grid.Column="0">
<Rectangle Width="200" Height="100" StrokeThickness="1" Stroke="Black">
<Rectangle.Fill>
<ImageBrush Viewport="0,0,0.3,0.5" ImageSource="../images/qq.gif" TileMode="FlipY"/>
</Rectangle.Fill>
</Rectangle>
</StackPanel>
<!--凹凸效果-->
<StackPanel Orientation="Vertical" Grid.Row="1" Grid.Column="1">
<Button Width="200" Height="50" FontSize="18" Content="凹凸效果">
<Button.BitmapEffect>
<BevelBitmapEffect BevelWidth="1" EdgeProfile="CurvedOut" LightAngle="0" Relief="0.1" Smoothness="0.1"/>
</Button.BitmapEffect>
</Button>
<Image Source="../images/qq.gif" Width="60" Height="60" Margin="6">
<Image.BitmapEffect>
<BevelBitmapEffect BevelWidth="1" EdgeProfile="CurvedOut" LightAngle="135" Relief="0.3" Smoothness="0.4"/>
</Image.BitmapEffect>
</Image>
<TextBlock Text="BevelWidth:指定斜面的宽度"/>
</StackPanel>
<!--浮雕效果-->
<StackPanel Grid.Row="2" Grid.Column="0">
<Image Source="../images/qq.gif" Width="60" Height="60">
<Image.BitmapEffect>
<EmbossBitmapEffect Relief="0.2" LightAngle="320"/>
</Image.BitmapEffect>
</Image>
</StackPanel>
<!--发光和阴影-->
<StackPanel Grid.Row="2" Grid.Column="1">
<TextBlock Text="发光用OuterGlowBitmapEffect,阴影用DropShadowBitmapEffect:" Margin="3" Padding="3" Style="{StaticResource ResourceKey=StyTextBlock}"/>
<TextBlock TextWrapping="Wrap" Style="{StaticResource ResourceKey=Desc}">
OuterGlowBitmapEffect=>GlowColor:光环发光的颜色;GlowSize:光环的厚度; Noise:光环的噪音级别(0~1);
<TextBlock.BitmapEffect>
<OuterGlowBitmapEffect GlowColor="Red" GlowSize="20" Noise="0.5" Opacity="0.4"/>
</TextBlock.BitmapEffect>
</TextBlock>
<TextBlock TextWrapping="Wrap" Margin="20">
DropShadowBitmapEffect=>Color:阴影的颜色; Direction:阴影的角度;Noise:阴影的噪音级别(0~1);ShadowDepth投影平面与阴影平面的距离;Softness:指定阴影的柔和度
<TextBlock.BitmapEffect>
<DropShadowBitmapEffect Color="Black" Direction="20" ShadowDepth="20" Softness="0.3" Opacity="0.4"/>
</TextBlock.BitmapEffect>
</TextBlock>
</StackPanel>
</Grid>
</Window>