transparency - How to create a semi transparent window in WPF that allows mouse events to pass through -


I am trying to create an effect similar to the light out / light dim feature in Adobe Lightroom (excluding WPF). / P>

What I tried was to create another window on my existing window, make it transparent and put semi transparent path geometry on it. But I want to be able to cross the mouse event through this semi-transparent window (down to windows).

This is a simplified version of me:

  & lt; Window x: Class = "Light Auto. Mask Window" xmlns = "http://schemas.microsoft.com/comfx/ 2006/xaml/Presentation" xmlns: x = "http://schemas.microsoft.com/winfx/2006 / Xaml "allows TranspriCi =" True "WindowStyle =" None "ShowInTaskbar =" False "Top =" True "Background =" Transparent "& gt; & Lt; Grid & gt; & Lt; Button horizontal alignment = "left" height = "20" width = "60" & gt; & Lt; / Button & gt; & Lt; Path isHitTestVisible = "False" stroke = "black" = "black" Opacity = "0.3" & gt; & Lt; Path.Data & gt; & Lt; RectangleGeometry Rect = "0,0,1000,1000" /> & Lt; /Path.Data> & Lt; / Path & gt; & Lt; / Grid & gt;  

The window is completely transparent, so places where the path is not covered, the mouse events pass. So far, so good. IsHitTestvisible Path is set to wrong on the object. That's why the mouse event will reach the other control on the same form (i.e. you can click on the button, because it is on the same form).

But the mouse event passes through objects on the windows below the object.

Any thoughts? Or better way to solve this problem?

Thanks

I have a similar problem and found a solution:

  Public Static Class WindowsServices {const int WS_EX_TRANSPARENT = 0x00000020; Const int GWL_EXSTYLE = (-20); [DllImport ("user32.dll")] steady extern c GetWindowLong (IntPtr hwnd, int index); [DllImport ("user32.dll")] Fixed extern int set window (intPtr hwnd, int index, int newStyle); Public Stable Zero SetWindowExTransparent (IntPtr hwnd) {var Extended style = GetWindowLong (hwnd, GWL_EXSTYLE); Set window long (hwd, gwl_exstyle, extended style | ws_EX_TRANSPARENT); }}  

For your window set:

  window style = any top not = true EnableTransparency = true  
< P> Add to the back window in the code:

  protected override zero onsource initial (EventArgs e) {base.OnSourceInitialized (e); Var hwnd = New WindowInteropHelper (this). Hindle; WindowsServices.SetWindowExTransparent (hwnd); }  

and voicemail - click-through window! See in the original answer:


Comments