WPF 投影
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2831062/
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
WPF drop shadow
提问by Petezah
Whenever I set the Border.Effect
property to a drop shadow effect every control contained within the control has a drop shadow.
每当我将Border.Effect
属性设置为阴影效果时,控件中包含的每个控件都有一个阴影。
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>
回答by Brad Cunningham
Two choices:
两种选择:
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:
选项 1:添加一个对其产生影响的边框元素作为您拥有的边框/矩形元素树的同级。像这样的东西:
<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>
Option 2: Put the rectangle as a sibling of the border element like this:
选项 2:将矩形作为边框元素的同级元素,如下所示:
<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
注意:您必须调整第二个解决方案的布局,使矩形排列在您想要的位置