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

Solution 1:

I've had similar problem and found a solution:

public static class WindowsServices
{
  const int WS_EX_TRANSPARENT = 0x00000020;
  const int GWL_EXSTYLE = (-20);

  [DllImport("user32.dll")]
  static extern int GetWindowLong(IntPtr hwnd, int index);

  [DllImport("user32.dll")]
  static extern int SetWindowLong(IntPtr hwnd, int index, int newStyle);

  public static void SetWindowExTransparent(IntPtr hwnd)
  {
    var extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
    SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT);
  }
}

for your window set:

WindowStyle = None
Topmost = true
AllowsTransparency = true

in code behind for the window add:

protected override void OnSourceInitialized(EventArgs e)
{
  base.OnSourceInitialized(e);
  var hwnd = new WindowInteropHelper(this).Handle;
  WindowsServices.SetWindowExTransparent(hwnd);
}

and voila - click-through window! See original answer in: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a3cb7db6-5014-430f-a5c2-c9746b077d4f

Solution 2:

What you described sounds like the expected behavior. One solution is to set the Fill to {x:Null} on the Path as that is the only sure way to make an object not hit test.

Solution 3:

I haveanother idea.

What if you made exactly ONE PIXEL, right under the mouse cursor, completely transparent? :]