Add input pass-through (not click-through) through transparent parts of a WinUI 3 window. #10746
-
Is there any way to add input passthrough through the transparent parts of a WinUI3 window? I don't just mean allow mouse clicks to go through the transparent bits, but ALL input like mouse move or drag, etc. I have been looking at this problem for a few days, but I haven't been able to get it to work. I want to be able to do something like the following WPF example (https://stackoverflow.com/a/77480302): Here is some sample code I am using: MainWindow.xaml:
MainWindow.xaml.cs:
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 3 replies
-
The solution shown in the WPF example is also valid in WinUI.There is no difference between them. public static void SetWindowExTransparent(IntPtr hwnd)
{
var extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT);
}
public static void SetWindowExNormal(IntPtr hwnd)
{
int extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle & ~WS_EX_TRANSPARENT);
} |
Beta Was this translation helpful? Give feedback.
-
I have edited the sample code I provide to show a working example with WPF and non-working example with WinUI. Code examples provided below: |
Beta Was this translation helpful? Give feedback.
-
A way in WinUI 3 is with Regions (test done in the other thread : #1247 (comment)) |
Beta Was this translation helpful? Give feedback.
-
I believe this will never work. WinUI 3 uses composition to draw its contents. The drawing is hardware accelerated and drawn using Direct3D. This means that the contents will never really be seen by the window itself. This means that the window will never know how to pass input through. This is easy to reproduce if you fall back to a Windows API window. If you create the windows using CreateWindowEx with the |
Beta Was this translation helpful? Give feedback.
-
Thank you @castorix ! I finally got it to work thanks to your suggestion of using regions. I used something like this after my toolbar control is loaded in my example:
Here is the full example of a working project with WinUI3 using regions to enable input through transparent regions: I will have to actively manage the region of the window as I move children controls inside my window or show dialogs, dropdowns, tooltips, or other controls, etc. It feels like this is something that could have been easily turned into a feature to bring WinUI3 closer to parity with WPF:
|
Beta Was this translation helpful? Give feedback.
Thank you @castorix ! I finally got it to work thanks to your suggestion of using regions.
I used something like this after my toolbar control is loaded in my example: