This question can seem quite odd but from all my experience I've gotten used to setting keyboard focus to the focusable element just by clicking it with the mouse; however, UserControl with the properties Focusable = true
and IsTabStop = true
came as a surprise to me because it gets keyboard focus via Tab but stays ignorant to mouse clicks.
Understanding Focus When an HTML element is able to handle keyboard input, it is said to have focus. Exactly one element is able to have focus in a time. In most browsers, users can move focus by pressing the Tab key and the Shift + Tab keys.
Keyboard focus refers to the element that is currently receiving keyboard input. There can be only one element on the whole desktop that has keyboard focus. In WPF, the element that has keyboard focus will have IsKeyboardFocused set to true .
Handle the click event on the UserControl and add this code to the eventhandler:
private void UserControl_OnMouseUp(object sender, MouseButtonEventArgs e)
{
Keyboard.Focus(sender as UserControl);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With