wpf 将 DropShadow 添加到自定义窗口(混合)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16730797/
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
Add DropShadow to a Custom made Window (Blend)
提问by xperator
I am creating a custom Window form using Blend. (by setting AllowTransparencyto True)
我正在使用Blend创建一个自定义 Window 表单。(通过设置AllowTransparency为True)
I've finished the design and it works pretty well. Now I want to add Shadow effect to it. (DropShadowEffect)
我已经完成了设计,效果很好。现在我想给它添加阴影效果。( DropShadowEffect)
I can't do that because the Window itself is hidden so the effect won't show. And it doesn't work on the main Grid. No luck with adding a border and give the shadow to it.
我不能这样做,因为 Window 本身是隐藏的,所以效果不会显示。它不适用于主网格。添加边框并为其添加阴影没有运气。
回答by xperator
Ok I found the answer. ( With some help from this page)
好的,我找到了答案。(在此页面的一些帮助下)
First of all, Set the window's AllowTransparencyto True. Then change it's Backgroundto No Brush
首先,将窗口设置AllowTransparency为True。然后改变它的Background到No Brush
Lets say you have something like this: (Ignore the Rectangle and Borders)
假设您有这样的事情:(忽略矩形和边框)


Then change the Grid's Backgroundto White color. Now click on your Window and Add about 15 pixels to its width and height.
然后将网格更改Background为白色。现在单击您的窗口并为其宽度和高度添加大约 15 个像素。


And change the Shadow settings:
并更改阴影设置:


Now you can see the shadow :)
现在你可以看到阴影了:)


I think you got the idea how this is working. Remember you can still play around with the Window height/weight and the Shadow settings to get a better effect.
我想你知道这是如何工作的。请记住,您仍然可以使用窗口高度/重量和阴影设置来获得更好的效果。

