Dot-Net

如何在 WPF 中實現嵌入陰影效果

  • June 2, 2015

我在 HTML 中設計了一個界面,並希望將其轉換為 WPF,但在插入陰影時遇到了麻煩。

box-shadow: inset 0 2px 7px 0 rgba(0, 0, 0, 0.5);

我正在尋找的效果在這個jsFiddle中,我怎樣才能將它準確地翻譯成 WPF?

更新

我目前基於理查茲的回答如下,但它仍然沒有顯示陰影嗎?

<Border Grid.Row="1" CornerRadius="3" Grid.Column="0"  Margin="13,0,12,0" BorderThickness="0"  BorderBrush="#d2d2d2" ClipToBounds="True" Background="#fff0f0f0" >
   <Border Background="Transparent" BorderBrush="Black"  CornerRadius="3" BorderThickness="0" Margin="0">
       <Border.Effect>
           <DropShadowEffect ShadowDepth="2" BlurRadius="7" Color="Black" Direction="270" Opacity="0.5"/>
       </Border.Effect>
   </Border>
</Border>

你可以嘗試這樣的事情,相應地調整厚度:

<Border Background="LightGray" BorderBrush="DarkGray" 
          BorderThickness="1" ClipToBounds="True">
 <Border Background="Transparent" BorderBrush="Black" 
             BorderThickness="0 2 7 0" Margin="-2">
   <Border.Effect>
     <DropShadowEffect ShadowDepth="0" BlurRadius="10"/>
   </Border.Effect>
 </Border>
</Border>

引用自:https://stackoverflow.com/questions/15500820