gpt4 book ai didi

wpf - 如何在透明矩形上绘制阴影?

转载 作者:行者123 更新时间:2023-12-04 20:11:18 24 4
gpt4 key购买 nike

当我向矩形添加投影位图效果时,投影会考虑矩形的透明度(有意义)。有没有办法在透明矩形上渲染阴影,“好像”矩形是不透明的?即会出现一个矩形的“洞”,带有阴影。

这是带有阴影的透明矩形的 XAML - 没有显示任何内容:

<Rectangle Fill="Transparent" Margin="10" Width="100" Height="100">
<Rectangle.BitmapEffect>
<DropShadowBitmapEffect/>
</Rectangle.BitmapEffect>
</Rectangle>

最佳答案

将其放入 Kaxaml。它使用 SystemDropShadowChrome 装饰器创建一个大小为 500x500 的透明矩形。投影的剪辑设置为排除矩形区域。

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:theme="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Canvas>
<theme:SystemDropShadowChrome Margin="0,0,5,5">
<Rectangle Width="500" Height="500" Fill="transparent"/>
<theme:SystemDropShadowChrome.Clip>
<CombinedGeometry GeometryCombineMode="Exclude">
<CombinedGeometry.Geometry1>
<RectangleGeometry Rect="0,0,505,505"/>
</CombinedGeometry.Geometry1>
<CombinedGeometry.Geometry2>
<RectangleGeometry Rect="0,0,500,500"/>
</CombinedGeometry.Geometry2>
</CombinedGeometry>
</theme:SystemDropShadowChrome.Clip>
</theme:SystemDropShadowChrome>
</Canvas>
</Page>

如果您希望投影具有圆角,请设置 CornerRadiusSystemDropShadowChrome随便(假设 10),然后 Geometry1LeftTop值为 10,然后是 RadiusXRadiusY每个 RectangleGeometry到 10。

关于wpf - 如何在透明矩形上绘制阴影?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2295589/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com