我正在使用自定义窗口处理ac #wpf应用程序(allowtransparency = true,resize = none,window style = none).
现在我想添加类似于zune pc软件的投影.我读到了这个,所包含的drophadoweffect并没有覆盖我的窗户的所有角度,据说它会杀死性能.
我想这样实现它:我为我的布局网格添加了一个边距,我在编程时最大化了应用程序.
添加可应用于网格的投影的最佳方法是什么,这不会破坏性能并在所有方向上投下阴影?
Par*_*hah 10
我尝试了这里发布的解决方案,但没有一个让我接近我想要的最终结果(见下面的截图).所以我尝试了几个不同的东西,并在这里发布我的解决方案,以防有人有兴趣实现类似的东西.顺便说一句:如果你能改进我的解决方案,请告诉我,因为我发现它现在有点多余.

现在好了,驱动此效果的代码:
<Window ...
WindowStyle="None" AllowsTransparency="True" Background="Transparent"
...>
<Border>
<Border.Effect>
// opacity does not need to be specified but it looks cooler when you do
<DropShadowEffect BlurRadius="20" ShadowDepth="0" Opacity="0.8"
Color="Blue" />
</Border.Effect>
// make sure the value for Grid Margin is the same as DropShadowEffect
// BlurRadius
<Grid Background="White" Margin="20">
// I tried setting borderthickness and borderbrush to the previous
// <Border> element but instead of the border being shown right after
// the grid and before the drop shadow, it would show after the drop
// shadow making the overall effect very ugly
<Border BorderThickness="1" BorderBrush="Black">
// now you can specify whatever you want to display in the window
<Grid>
....
</Grid>
</Border>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
DropShadowEffect不会“降低性能”......它是使用硬件加速渲染的,并且在窗口上渲染阴影对于当前的 GPU 来说并不是什么大问题。您可能会混淆DropShadowBitmapEffect,它是软件呈现的。无论如何,所有BitmapEffects在 3.5 SP1 中都已过时,在 4.0 中根本不起作用,只能Effects现在使用
-75 的方向、2 的 ShadowDepth 和 27 的 BlurRadius 对我有帮助。
最好的方法是使用 Blend 来完成这些操作。
华泰
| 归档时间: |
|
| 查看次数: |
8249 次 |
| 最近记录: |