我有一个包含这些值的窗口:
WindowState="Maximized"
AllowsTransparency="True"
Opacity="0.5"
WindowStyle="None"
此窗口位于其他窗口的顶部(作为弹出窗口),其中包含特定位置的内容。
我有新要求。该窗口必须从下面的窗口显示一个矩形区域。换句话说,我必须在这个窗口中设置一个“洞”,它将是完全透明的(没有不透明度值)。 直到这一刻我才想出办法让这个透明的洞。
希望得到一个想法...
答案 0 :(得分:10)
我找到了一种解决方案:
这是一个弹出窗口,位于另一个窗口的顶部,并在所需位置包含另一个窗口的孔:
Window的标题:
WindowState="Maximized"
AllowsTransparency="True"
WindowStyle="None"
Window的内容:
<Window.Background >
<SolidColorBrush x:Name="BackgroundBrush" Color="WhiteSmoke" Opacity="0" ></SolidColorBrush>
</Window.Background>
<Canvas x:Name="ContectHolder" >
<Path Stroke="Black" Fill="WhiteSmoke" Opacity="0.8">
<Path.Data>
<CombinedGeometry GeometryCombineMode="Exclude">
<CombinedGeometry.Geometry1 >
<RectangleGeometry Rect="0,0,2000,2000" />
</CombinedGeometry.Geometry1>
<CombinedGeometry.Geometry2>
<RectangleGeometry Rect="75,75,400,900" />
</CombinedGeometry.Geometry2>
</CombinedGeometry>
</Path.Data>
</Path>
</Canvas>
答案 1 :(得分:4)
尽量避免AllowTransparency = true,这是非常错误和缓慢的。
你可以PInvoke SetWindowRgn创建一个任何形状的窗口: