WPF:无焦点窗口

时间:2010-04-19 19:58:39

标签: wpf focus

我正在开发WPF触摸屏键盘。

我需要知道如何使主窗口不可聚焦,因此当我点击虚拟键盘按钮时,其他窗口将接收输入。

简单地将“Focusable =”False“”应用于主窗口,并且所有子控件都不起作用。

3 个答案:

答案 0 :(得分:0)

我认为有一个可点击的属性可以设置为false,这会停止接收点击消息的表单。

答案 1 :(得分:0)

当你点击它时,使用Popup而不是Window来解决问题。

答案 2 :(得分:0)

从这里开始:https://social.msdn.microsoft.com/Forums/vstudio/en-US/41ca3605-247c-4c5b-ac5d-74ce5abd7b92/making-a-window-invisible-to-mouse-events-ishittestvisiblefalse-not-working?forum=wpf

我已经想出如何做到这一点。关键是窗口扩展样式的WS_EX_TRANSPARENT标志。您可以像往常一样设置最顶层的属性,然后此代码负责使窗口对鼠标点击透明:

代码段

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

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

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

protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);

// Get this window's handle
IntPtr hwnd = new WindowInteropHelper(this).Handle;

// Change the extended window style to include WS_EX_TRANSPARENT
int extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT);
}
相关问题