WPF 陰影效果


  制作WPF的陰影效果可以有很多種,貌似后來性能不好,然后被微軟給X掉了。現在只有幾個是可以用的,先暫時學習下現在有的,等以后看看用什么來代替原來的那些效果。

1.首先最常見的一個陰影效果的類是DropShadowEffect。它有幾種比較有用的屬性比如:Color設置顏色,Direction設置投影的方向,ShadowDepth設置投影距紋理下方的距離,Opacity設置透明度等等。角度的設置是這樣的:

 

下面是一個例子和效果:

View Code
<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計算模糊的曲線的值等等。

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

 

3.好吧貌似沒撒能用的了,不過還可以用TranslateTransform來疊兩個同樣的東西來顯示弄出陰影效果。

View Code
        <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.最后弄張相框類型的陰影圖片來玩玩。

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

=。=

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM