【问题标题】:Making a transparent hole in an overlay WPF在覆盖 WPF 中制作透明孔
【发布时间】:2015-09-08 22:38:38
【问题描述】:

我正在尝试在 WPF 中复制以下效果。我有一个 Grid 控件,其中的边框背景颜色为 #000000,不透明度为 0.7,内容呈现器像这样......

<Grid>
    <Border Background="#000000" Opacity="0.7" />
    <ContentPresenter ... />
</Grid>

我为我的控件内容添加了一个椭圆以尝试获得效果,但我从那里到达了一个路障。

<Control:SomeControl>
    <Ellipse Fill="Transparent" />
</Control:SomeControl>

感谢任何帮助。

【问题讨论】:

    标签: .net wpf wpf-controls


    【解决方案1】:

    您可以设置覆盖元素的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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-10
      • 1970-01-01
      • 2017-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-08
      相关资源
      最近更新 更多