簡體   English   中英

在疊加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>

任何幫助表示贊賞。

在此處輸入圖片說明

您可以設置overlay元素的Clip屬性(例如下面的Rectangle)。 請注意,疊加層必須在其他元素之上。

<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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM