I want to send a mouse click to the application behind a control. I have a Topmost transparent window and some controls in it. I would like to be able to send click through some of that controls.
I have already tried setting the property IsHitTestVisible="False" to the control, but it doesn´t work. It doesn´t send click through the control to desktop for example.
I´ve also tried the solution proposed in this question: How to create a semi transparent window in WPF that allows mouse events to pass through
And it works, but I would like to make transparent some controls, not the window.
How could I apply the solution to that question to a single control, for example an ellipse?
The 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);
}
}
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
var hwnd = new WindowInteropHelper(this).Handle;
WindowsServices.SetWindowExTransparent(hwnd);
}