一、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>