在覆盖 WPF 中制作透明孔
Making a transparent hole in an overlay WPF
我正在尝试在 WPF 中复制以下效果。我有一个 Grid 控件,其中的边框背景颜色为 #000000,不透明度为 0.7,内容呈现器如下所示...
<Grid>
<Border Background="#000000" Opacity="0.7" />
<ContentPresenter ... />
</Grid>
我在我的控件内容中画了一个椭圆以尝试获得效果,但我从那里遇到了障碍。
<Control:SomeControl>
<Ellipse Fill="Transparent" />
</Control:SomeControl>
感谢任何帮助。
您可以设置覆盖元素的 Clip
属性(如下面的矩形)。请注意,叠加层必须位于其他元素之上。
<Grid>
<TextBlock Margin="80,80" Text="Some Text" FontSize="32"/>
<Rectangle Fill="Black" Opacity="0.7">
<Rectangle.Clip>
<CombinedGeometry GeometryCombineMode="Exclude">
<CombinedGeometry.Geometry1>
<RectangleGeometry Rect="0,0,10000,10000"/>
</CombinedGeometry.Geometry1>
<CombinedGeometry.Geometry2>
<EllipseGeometry Center="100,100" RadiusX="50" RadiusY="50"/>
</CombinedGeometry.Geometry2>
</CombinedGeometry>
</Rectangle.Clip>
</Rectangle>
</Grid>
我正在尝试在 WPF 中复制以下效果。我有一个 Grid 控件,其中的边框背景颜色为 #000000,不透明度为 0.7,内容呈现器如下所示...
<Grid>
<Border Background="#000000" Opacity="0.7" />
<ContentPresenter ... />
</Grid>
我在我的控件内容中画了一个椭圆以尝试获得效果,但我从那里遇到了障碍。
<Control:SomeControl>
<Ellipse Fill="Transparent" />
</Control:SomeControl>
感谢任何帮助。
您可以设置覆盖元素的 Clip
属性(如下面的矩形)。请注意,叠加层必须位于其他元素之上。
<Grid>
<TextBlock Margin="80,80" Text="Some Text" FontSize="32"/>
<Rectangle Fill="Black" Opacity="0.7">
<Rectangle.Clip>
<CombinedGeometry GeometryCombineMode="Exclude">
<CombinedGeometry.Geometry1>
<RectangleGeometry Rect="0,0,10000,10000"/>
</CombinedGeometry.Geometry1>
<CombinedGeometry.Geometry2>
<EllipseGeometry Center="100,100" RadiusX="50" RadiusY="50"/>
</CombinedGeometry.Geometry2>
</CombinedGeometry>
</Rectangle.Clip>
</Rectangle>
</Grid>