WPF 實現陰影效果


一、WPF最常見的一個陰影效果的類是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>

 
二、模糊效果的類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>

 
三、用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>

 


免責聲明!

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



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