Create a transparent hole inside the window background - WPF

I have a window with these values:

WindowState="Maximized" AllowsTransparency="True" Opacity="0.5" WindowStyle="None" 

This window comes out on top of another window (like a pop-up window) with the contents on it in a specific place.

I have a new requirement. This window should display the rectangular area from the window below. In other words, I have to set a β€œhole” in this window that will be completely transparent (without opacity value). Until this moment, I could not figure out how to make this transparent hole.

Hope to get an idea ...

+7
transparency wpf
source share
2 answers

try to avoid AllowsTransparency = true, it is very buggy and slow.

you can PInvoke SetWindowRgn create a window of any shape:

  • Use CreateRectRgn twice, once for the rectangle bordering the window, and once for the hole.
  • Use CombineRgn with RGN_AND as the 4th parameter to get an area with a hole in it.
  • Call SetWindowRgn to apply the region to the window.
  • Remember to delete all regions except those that you passed to SetWindowRgn
+3
source share

I found some solution for her:

this is a popup that is on top of another window and contains a hole in another window in the right place:

Window title:

  WindowState="Maximized" AllowsTransparency="True" WindowStyle="None" 

Window contents:

 <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> 
+9
source share

All Articles