Do mouse clicks bring keyboard focus to focusable controls by default?

China☆狼群 提交于 2019-12-23 07:43:03

问题


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.


回答1:


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);
}


来源:https://stackoverflow.com/questions/15600017/do-mouse-clicks-bring-keyboard-focus-to-focusable-controls-by-default

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!