• WPF 实现阴影效果


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

    下面是一个例子和效果:

    <TextBlock Text="HELLO WORLD" 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="Hello world" Foreground="Green" HorizontalAlignment="Center" Margin="20" FontSize="36">
                <TextBlock.Effect>
                    <BlurEffect Radius="4" KernelType="Box" />
                </TextBlock.Effect>
            </TextBlock>

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

        <Grid>
            <TextBlock Text="helloworld" Foreground="Black" HorizontalAlignment="Center" Margin="20" FontSize="36">
                    <TextBlock.RenderTransform>
                        <TranslateTransform X="3" Y="3" />
                    </TextBlock.RenderTransform>
            </TextBlock>
            <TextBlock Text="helloworld" 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="C:UserslenovoDownloads1.jpg" Stretch="Uniform" />
            <Border.Effect>
                <DropShadowEffect Color="Black" BlurRadius="16" ShadowDepth="0" Opacity="1" />
            </Border.Effect>
        </Border>



     

  • 相关阅读:
    架构优秀文章汇总
    SpringCloud-Hystrix 注解配置Hystrix && 和FeignClient集成 (转)
    SpringCloud-Hystrix(服务熔断,服务降级)(1)
    java 锁 -乐观锁、悲观锁  Volatile
    JS OOP -02 深入认识JS中的函数
    JS OOP -01 面向对象的基础
    JS OOP 概述
    拆表策略
    双重检查加锁机制(并发insert情况下数据重复插入问题的解决方案)
    C# 理解lock
  • 原文地址:https://www.cnblogs.com/xinyuyuanm/p/3178005.html
Copyright © 2020-2023  润新知