【问题标题】:Trying to catch keyboard focus but试图抓住键盘焦点,但
【发布时间】:2021-07-14 21:25:10
【问题描述】:

有没有可能看到项目键盘焦点属于哪个对象?抓不住。

提前感谢您的任何提示。

【问题讨论】:

标签: c# wpf focus


【解决方案1】:

使用FocusManager.GetFocusedElement 返回自然选中的控件。

 Control focusedControl = (Control)FocusManager.GetFocusedElement(this);

使用Keyboard.FocusedElement 控制键盘选择。

 Control focusedControl = (Control)Keyboard.FocusedElement;

两者都返回IInputElement 可以转换为control

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-30
    • 1970-01-01
    • 2013-08-12
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多