鼠标点击是否将键盘焦点默认设置为可对焦控件? [英] Do mouse clicks bring keyboard focus to focusable controls by default?

查看:151
本文介绍了鼠标点击是否将键盘焦点默认设置为可对焦控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题看起来很奇怪,但是从我用来将键盘焦点设置为可聚焦元素的所有经验来看,只需用鼠标点击即可。然而,UserControl的属性 Focusable = true IsTabStop = true 对我来说是一个惊喜,因为它获得了键盘焦点通过标签,但保持无知点击鼠标。

解决方案

处理UserControl上的click事件并将此代码添加到事件处理程序: / b>

  private void UserControl_OnMouseUp(object sender,MouseButtonEventArgs e)
{
Keyboard.Focus(sender as UserControl) ;
}


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.

解决方案

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

这篇关于鼠标点击是否将键盘焦点默认设置为可对焦控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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