Win7 WPF Alt+Tab 焦点怪异
经过几个小时的谷歌搜索后,我无法找到有关此问题的任何评论。我们有一个带有透明背景的 WindowStyle=None 窗口,并且允许透明并且不会显示在任务栏中,这一切都很正常。这是 XAML,您可以自行测试:
<Window x:Class="AltTabTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="TestWindow" Title="TestWindow"
WindowStyle="None" AllowsTransparency="True" ResizeMode="NoResize"
Background="Transparent" ShowInTaskbar="False"
Width="816" Height="820">
<Grid>
<Border BorderThickness="0" Background="LightBlue" CornerRadius="15" />
</Grid>
现在奇怪的是,一旦编译并运行此窗口,请按照以下步骤操作:
- 单击“显示桌面”以隐藏所有应用程序
- Alt+Tab 返回到 WPF 测试应用程序
- 单击浅蓝色边框区域外部(到桌面工作区)
- 观察 WPF 测试应用程序神奇地消失
- 可选择 Alt+Tab 到任何其他正在运行的应用程序,并观察 WPF 测试应用程序神奇地重新出现
所以我的问题是:这里到底发生了什么?!这是预期的行为吗?如果是这样,有什么办法可以解决吗?
感觉在 Alt+Tab 解决后,WPF 应用程序并没有真正获得焦点。请注意,这是在 Windows 7 中进行测试,我还没有能力在 Vista 或 XP 中进行测试。我想要一种方法来强制应用程序真正获得焦点,但如果这不可能,那么我想知道是否有一种方法可以捕获并忽略 Alt+Tab 操作。本次修复的应用程序是锁定模式应用程序,因此用户永远无法真正摆脱在桌面上运行的应用程序。任何建议、例子、见解或正确方向的观点将不胜感激,谢谢! =)
After a couple hours of Googling I haven't been able to find any comments on this issue. We have a WindowStyle=None
window with transparent background and allows transparency and does not show in taskbar, all pretty normal. Here's the XAML so you can test for yourself:
<Window x:Class="AltTabTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="TestWindow" Title="TestWindow"
WindowStyle="None" AllowsTransparency="True" ResizeMode="NoResize"
Background="Transparent" ShowInTaskbar="False"
Width="816" Height="820">
<Grid>
<Border BorderThickness="0" Background="LightBlue" CornerRadius="15" />
</Grid>
Now what's bizarre is once you compile and run this window, follow these steps:
- Click on Show Desktop to hide all apps
- Alt+Tab back to the WPF Test App
- Click outside of the Light Blue border area (to the desktop workspace)
- Observe WPF Test App magically disappear
- Optionally Alt+Tab to any other running app and observe WPF Test App magically re-appear
So my question is: what the heck is going on here?! Is this expected behavior? If so, is there any way around it?
It feels like the WPF app is not truly getting focus after the Alt+Tab is resolved. Please note this is being tested in Windows 7 and I have not had the capability to test this in Vista or XP. I'd like a way to force the app to truly get focus, but if that's not possible then I'm wondering if there's a way to trap and ignore Alt+Tab actions. The app this is intended to fix is a lockdown mode app so users should never be able to truly get away from it running on the desktop. Any advice, examples, insight or point in the right direction would be appreciated, thanks! =)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据 Spy++ 的说法,问题是当您使用 WindowStyle="None" 设置窗口时,当您使用 alt-tab 切换到该窗口时,该窗口不再接收 WM_ACTIVATE 消息。设置AllowsTransparency =“True”会禁用窗口的命中测试,因此当您单击蓝色矩形之外时,唯一返回true的HitTest是桌面的HitTest。
因为 WM_ACTIVATE 从未被触发,所以 MinimizeAllWindowsToDesktop 东西无法识别任何活动窗口,因此当它收到您单击桌面的通知时,桌面正在呈现,就像没有激活窗口并且您正在桌面上做一些工作一样(此函数的预期行为)。
我不知道为什么在 Win7 中窗口没有收到 WM_ACTIVATE 消息。
编辑:
没关系,这看起来只是 WPF 和 Windows 7 中的一个错误。无论窗口的设置如何,此行为都会持续存在。
According to Spy++ the problem is that the window when set with WindowStyle="None" is not receiving a WM_ACTIVATE message anymore when you alt-tab to it. Having AllowsTransparency="True" is disabling hit testing for the window, so when you click beyond the blue rectangle the only HitTest returning true is that of the desktop.
Because WM_ACTIVATE was never fired, the MinimizeAllWindowsToDesktop thingey doesn't recognize any active windows and so when it receives the notification that you clicked on the desktop the desktop is rendering just as it would had no windows activated and you were doing some work on the desktop (the expected behavior for this function).
I don't know why in Win7 the window is not receiving the WM_ACTIVATE message though.
EDIT:
Nevermind, this looks like it's just a bug in WPF and Windows 7. This behavior persists no matter what the settings of the window.