I am trying to make a window that acts as an "overlay" on top of everything else on my screen. It should not interfere with input to other windows, so I should be able to click through to whatever is under it, with a few exceptions, like small buttons on the overlay that I can click to "dismiss" other UI elements on the overlay.
What I have found, and the problems with each:
- Setting
Topmost="True"
on the window. There is no problem with this. This does exactly what I want, it makes my window always drawn on top of other windows. - Making the window background to
{x:Null}
and addingAllowsTransparency="True"
andWindowStyle="None"
on the Window. This allows click through allows clicking through the transparent parts, and allows clicking on buttons that are visible, however, since the click-through only works on invisible things, that's not very useful. Can never, you know, actually display any information on the overlay or that breaks the click-through behavior. Doing the above, but also setting
IsHitTestVisible="False"
on elements that I want to be able to click through. This disabled interacting with the controls using the mouse, but it doesn't allow the clicks to pass through to the window beneath it.Using the
SetWindowLong
method from this accepted answer. The problem with this is that it makes the entire window click through. You are no longer able to make certain buttons on the overlay clickable.- Using the
SetWindowLong
method from above, but pass it thehwnd
of the button and make the button not transparent to clicks. This does not work. It's actually not even possible to do because unlike in WinForms, WPF buttons are not windows and they do not have window handles.
I've tried toggling the window's extended style to not be "transparent" when the mouse is over the button and make it transparent again when the mouse leaves the button, but that also does not work because when it is set to be transparent then it also does not pick up MouseMove, MouseEnter, or MouseLeave events.