Get the current item / control in the WPF window

How can I get the current element / control in WPF from code that is not part of either a window or a user control?

+48
wpf focus
Oct. 15 '13 at 22:15
source share
1 answer

It depends on the type of focus you are using, Logical or Keyboard .

Keyboard focus refers to an element that receives keyboard input, and logical focus refers to an element in the focus area that has focus.

FocusManager receives an element with logical focus within the specified focus area, in this case Window ( this ):

 IInputElement focusedControl = FocusManager.GetFocusedElement(this); 

Keyboard will return an item with the current keyboard input focus:

 IInputElement focusedControl = Keyboard.FocusedElement; 
+84
Oct 15 '13 at 22:50
source share
— -



All Articles