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

mac*_*nir 4 wpf xaml

当我将阴影位图效果添加到矩形时,阴影会考虑矩形的透明度(有意义).有没有办法在透明矩形上渲染阴影'就好像'矩形是不透明的?即出现的是一个长方形的"洞",带有阴影.

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

<Rectangle Fill="Transparent" Margin="10" Width="100" Height="100">
  <Rectangle.BitmapEffect>
    <DropShadowBitmapEffect/>
  </Rectangle.BitmapEffect>
</Rectangle>
Run Code Online (Sandbox Code Playgroud)

mos*_*ald 5

把它放入Kaxaml.它创建一个大小为500x500的透明矩形,带有SystemDropShadowChrome装饰器.投影的剪辑设置为排除Rectangle的区域.

<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>
Run Code Online (Sandbox Code Playgroud)

如果你希望你的阴影有圆角,然后设置CornerRadiusSystemDropShadowChrome,以什么(比方说10),那么Geometry1LeftTop值10,然后RadiusXRadiusY每个RectangleGeometry为10.