获取目前专注元/控制在一个WPF窗口 [英] Get currently focused element/control in a WPF window

查看:198
本文介绍了获取目前专注元/控制在一个WPF窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何获得在WPF这既不是一个窗口,也不是用户控制部分当前焦点元/控制从code?

How can I acquire the currently focused element/control in WPF from code that is part of neither a window nor an user control?

推荐答案

根据焦点的你逻辑键盘<之后的类型/ code>

Depending of the type of focus you are after Logical or Keyboard

键盘焦点指接收键盘输入和逻辑焦点是指元素具有焦点的对焦范围的元素。

Keyboard focus refers to the element that receives keyboard input and logical focus refers to the element in a focus scope that has focus.

的FocusManager

获取与指定的焦点范围内的逻辑焦点的元件在这种情况下,窗口(本)。

gets the element with logical focus within the specified focus scope in this case the Window (this).

  var focusedControl = FocusManager.GetFocusedElement(this);

键盘

将返回元件与当前键盘输入焦点

will return the element with the current keyboard input focus

  var focusedControl =  Keyboard.FocusedElement;

这篇关于获取目前专注元/控制在一个WPF窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆