wpf 如何在WPF中实现插入阴影效果

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15500820/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 08:10:16  来源:igfitidea点击:

How to achieve inset shadow effect in WPF

.netwpfsilverlightxamlstyles

提问by Chris

I have designed an interface in HTML and wish to translate this into WPF but am having troubles with inset shadow.

我用 HTML 设计了一个界面,并希望将其转换为 WPF,但在插入阴影方面遇到了麻烦。

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

The effect im looking for is here in this jsFiddle, how can I translate this into WPF exactly?

我正在寻找的效果在这个jsFiddle 中,我怎样才能把它准确地转换成 WPF?

Update

更新

What I currently have based on Richards answer is below, its still not showing a shadow though?

我目前基于理查兹的回答的内容如下,但它仍然没有显示阴影?

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

回答by Dutts

You could try something like this, tweaking the thicknesses accordingly:

你可以尝试这样的事情,相应地调整厚度:

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