zoukankan      html  css  js  c++  java
  • WPF 阴影效果

    WPF 阴影效果

      制作WPF的阴影效果可以有很多种,貌似后来性能不好,然后被微软给X掉了。现在只有几个是可以用的,先暂时学习下现在有的,等以后看看用什么来代替原来的那些效果。

    1.首先最常见的一个阴影效果的类是DropShadowEffect。它有几种比较有用的属性比如:Color设置颜色,Direction设置投影的方向,ShadowDepth设置投影距纹理下方的距离,Opacity设置透明度等等。角度的设置是这样的:

    下面是一个例子和效果:

    复制代码
    <TextBlock Text="Shadow Test" Foreground="Green" HorizontalAlignment="Center" Margin="20" FontSize="36">
                <TextBlock.Effect>
                    <DropShadowEffect Color="Black" Direction="0" ShadowDepth="5" Opacity="1" />
                </TextBlock.Effect>
            </TextBlock>
    复制代码

    2.接下来是模糊效果的类BlurEffect。可以设置Radius模糊效果曲线的半径,KernelType计算模糊的曲线的值等等。

    复制代码
            <TextBlock Text="Shadow Test" Foreground="Green" HorizontalAlignment="Center" Margin="20" FontSize="36">
                <TextBlock.Effect>
                    <BlurEffect Radius="4" KernelType="Box" />
                </TextBlock.Effect>
            </TextBlock>
    复制代码

    3.好吧貌似没撒能用的了,不过还可以用TranslateTransform来叠两个同样的东西来显示弄出阴影效果。

    复制代码
            <Grid>
                <TextBlock Text="Transform Shadow" Foreground="Black" HorizontalAlignment="Center" Margin="20" FontSize="36">
                    <TextBlock.RenderTransform>
                        <TranslateTransform X="3" Y="3" />
                    </TextBlock.RenderTransform>
                </TextBlock>
                <TextBlock Text="Transform Shadow" Foreground="Green" HorizontalAlignment="Center" Margin="20" FontSize="36" />
            </Grid>
    复制代码

    4.最后弄张相框类型的阴影图片来玩玩。

    复制代码
            <Border SnapsToDevicePixels="True" BorderBrush="Red" BorderThickness="4" CornerRadius="5" Margin="20" HorizontalAlignment="Center" VerticalAlignment="Center">
                <Image Width="200" Source="ImageWill.jpg" Stretch="Uniform" />
                <Border.Effect>
                    <DropShadowEffect Color="Black" BlurRadius="16" ShadowDepth="0" Opacity="1" />
                </Border.Effect>
            </Border>
    复制代码

    =。=

  • 相关阅读:
    .NET中26个优化性能方法
    通过纯真IP地址实现根据用户地址显示信息
    jQuery中json中关于带有html代码网页的处理
    gb2312提交的url编码转换成utf8的查询
    c# Bitmap byte[] Stream 文件相互转换
    WebClient 上传文件
    进程监控模块配置与使用 ------ACE(开源项目)
    boost配置
    C++学习总结3
    SAE云平台的使用
  • 原文地址:https://www.cnblogs.com/changbaishan/p/9366451.html
Copyright © 2011-2022 走看看