WPF 窗口 GotFocus / LostFocus

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14999059/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 07:39:18  来源:igfitidea点击:

WPF Window GotFocus / LostFocus

wpfwindowfocus

提问by Karnalta

I have a simple task to accomplish, or at least in appearance ...

我有一个简单的任务要完成,或者至少在外观上......

I'd like to handle the fact that a window is currently the current selected window in the Windows environment or not.

我想处理这样一个事实,即窗口当前是否是 Windows 环境中的当前选定窗口。

I thought I had just to handle the two event LostFocus and GotFocus of my window, but they don't fired. I can select the window or click elsewhere on the desktop, none of the events are triggered..

我以为我只需要处理窗口的 LostFocus 和 GotFocus 两个事件,但它们没有触发。我可以选择窗口或单击桌面上的其他地方,没有触发任何事件..

The GotFocus event only fired when I reduce or maximize the window.

GotFocus 事件仅在我缩小或最大化窗口时触发。

Am I doing something wrong ?

难道我做错了什么 ?

Thank you.

谢谢你。

回答by Florian Gl

Try using the Activated/Deactivated event. GotFocus/LostFocus is intended to be used only with controls (e.g. it fires when you click on controls inside the window).

尝试使用 Activated/Deactivated 事件。GotFocus/LostFocus 旨在仅与控件一起使用(例如,当您单击窗口内的控件时会触发)。