目录
Effect
DropShadowEffect 阴影
属性:
Direction 表示阴影的显示方向:逆时针角度值
Color 颜色
BlurRadius 模糊程度
Opacity 透明度
ShadowDepth 阴影深度
<Border Width="100" Height="50" Background="Orange">
<Border.Effect>
<DropShadowEffect Color="Red" ShadowDepth="20" BlurRadius="15" Direction="-45" Opacity="0.5"/>
</Border.Effect>
</Border>
也可以增加文字特殊高亮:
<TextBlock Text="Hello">
<TextBlock.Effect>
<DropShadowEffect Color="Gray" ShadowDepth="0" BlurRadius="5"/>
</TextBlock.Effect>
</TextBlock>
设置边框内为阴影,边框外没有阴影显示:
<Border Width="100" Height="50" BorderBrush="Green" BorderThickness="1"
CornerRadius="10">
<Border.Clip>
<!--用Clip中自定义分割,可以分割圆角,如果没有圆角直接分割即可-->
<RectangleGeometry Rect="0 0 100 50" RadiusX="10" RadiusY="10" />
</Border.Clip>
<TextBlock Text="Hello" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<Border.Effect>
<!--当边边非透明,就有阴影-->
<DropShadowEffect Color="Red" ShadowDepth="0" BlurRadius="5" Opacity="0.5"/>
</Border.Effect>
</Border>
BlurEffect 模糊
<Border Width="100" Height="50" Background="Green">
<Border.Effect>
<BlurEffect Radius="10" />
</Border.Effect>
</Border>
GrayscaleEffect 自定义去色效果
接下来在代码中使用演示:
下载之后,记的修改文件路径,确保能够正确找到ps文件
放在同级目录下:
<Window.Effect>
<!--DesaturationFactor区间是0-1 0是全灰,1是原色-->
<local:GrayscaleEffect DesaturationFactor="0" />
</Window.Effect>
原来的颜色全部灰色处理:
OpacityMask 透明模班设置
<TextBlock Text="Hello" Name="tb" HorizontalAlignment="Center"/>
<Border Width="100" Height="50" RenderTransformOrigin="0.5,0.5">
<Border.RenderTransform>
<ScaleTransform ScaleY="-1"/>
</Border.RenderTransform>
<Border.Background>
<VisualBrush Visual="{Binding ElementName=tb}" />
</Border.Background>
<Border.OpacityMask>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<!--由于上面写的有颠倒,所以这边设置的会是反着-->
<GradientStop Color="Black" Offset="1"/>
<GradientStop Color="Transparent" Offset="0"/>
</LinearGradientBrush>
</Border.OpacityMask>
<Border.Effect>
<BlurEffect Radius="2" />
</Border.Effect>
</Border>
平面渲染C#处理
Path 绘图路径
xaml中设置:
C#中设置以及显示:
很明显C#中的设置改变了Path的路线
// C#代码设置Path
string strPath = "M0 0 10 100";
// 注意转换即可
this.path.Data = PathGeometry.Parse(strPath);
SolidColorBrush 颜色画刷
// 1、可以根据Brushes直接设置
this.br.Background = Brushes.AliceBlue;
// 2、根据RGB进行设置
this.br.Background = new SolidColorBrush(Color.FromRgb(255,0,0));
// 3、根据ARGB进行设置 比RGB多一个第一个16进制数字,表示颜色的深浅度,数字越大越深,反之越浅
this.br.Background = new SolidColorBrush(Color.FromArgb(255,0,0,0));
// 4、根据#二十六进制进行表示
this.br.Background = new BrushConverter().ConvertFrom("#FFCAC2AD") as SolidColorBrush;