C#C
C#3y ago
Ossie

❔ WPF Window click-thru/non-clickable

Hey, how is it possible to make a WPF Window click-thru/non-clickable. I don't want to highlight or click on it in any way. The window is for an overlay, so I needs to be uninteractable, so you don't click it accidently.

I already tried the following without success:

  1. Using SetWindowLong
    ```cs
    [DllImport("user32.dll", EntryPoint = "SetWindowLongA", SetLastError = true, CharSet = CharSet.Unicode)]
    public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("user32.dll", EntryPoint = "GetWindowLongA", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern int GetWindowLong(IntPtr hWnd, int nIndex);

public const int WS_EX_TRANSPARENT = 0x00000020;
public const int GWL_EXSTYLE = (-20);

public static void MakeTransParent(IntPtr hWnd)
{
int extendedStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
SetWindowLong(hWnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT);
}
`` This didn't work, and its still clickable for some reason. Is it because im trying to do it from inside the WPF windows own code? 2. IsHitTestVisible I tried setting IsHitTestVisible to false`, both in the XAML and after instancing the window. Still clickable...


Any help is appreciated, as I can't seem to find anything online that is not the methods listed above.


Thanks
Was this page helpful?