WPF投影 [英] WPF drop shadow

查看:160
本文介绍了WPF投影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我将Border.Effect属性设置为阴影效果时,该控件中包含的每个控件都会具有阴影.

Whenever I set the Border.Effect property to a drop shadow effect every control contained within the control has a drop shadow.

有没有一种方法可以将阴影仅设置在边框上,而不是边框​​中包含的每个控件?

Is there a way to set the shadow just to the border and not every control contained in the border?

这是我的代码的简短示例:

Here is a short example of my code:

<Grid>
 <Border Margin="68,67,60,67" BorderBrush="Black" BorderThickness="1" CornerRadius="10">
  <Border.Effect>
   <DropShadowEffect/>
  </Border.Effect>
  <Rectangle Fill="White" Stroke="Black" Margin="37,89,118,98" />
 </Border>
</Grid>

推荐答案

两个选择:

选项1:添加一个具有边框效果的边框元素,作为您拥有的边框/矩形元素树的同级元素.像这样:

Option 1: Add a border element with the effect on it as a sibling of the border / rectangle element tree you have. Something like this:

<Grid>
    <Border Margin="68,67,60,67"
            BorderBrush="Black"
            BorderThickness="1"
            CornerRadius="10">
        <Border.Effect>
            <DropShadowEffect />
        </Border.Effect>
    </Border>
    <Border Margin="68,67,60,67"
            BorderBrush="Black"
            BorderThickness="1"
            CornerRadius="10">

        <Rectangle Fill="White"
                   Stroke="Black"
                   Margin="37,89,118,98">
        </Rectangle>
    </Border>

</Grid>

选项2:将矩形作为边框元素的同级放置,如下所示:

Option 2: Put the rectangle as a sibling of the border element like this:

   <Grid>
    <Border Margin="68,67,60,67"
            BorderBrush="Black"
            BorderThickness="1"
            CornerRadius="10">
        <Border.Effect>
            <DropShadowEffect />
        </Border.Effect>
    </Border>
    <Rectangle Fill="White"
               Stroke="Black"
               Margin="37,89,118,98">
    </Rectangle>

</Grid>

注意:您将不得不在第二种解决方案上调整布局,以使矩形排列在您想要的位置

NOTE: You will have to tweak the layout on the second solution to make the rectangle line up where you want it

这篇关于WPF投影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆