如何使CheckBox的焦点边框出现时调用CheckBox.Focus()? [英] How to make CheckBox focus border appear when calling CheckBox.Focus()?

查看:709
本文介绍了如何使CheckBox的焦点边框出现时调用CheckBox.Focus()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户选中一个复选框以使其对焦时,复选框周围将显示一个虚线边框,以指示其具有焦点。

When the user tabs into a CheckBox to give it focus, a dotted border appears around the CheckBox to indicate that it has focus.

当CheckBox通过调用 myCheckBox.Focus()的代码集中时,

When the CheckBox gets focused by code calling myCheckBox.Focus(), no such indicator appears (even though pressing the space bar toggles the state).

当我以编程方式集中CheckBox时,如何使CheckBox的焦点边框出现?

How can I make the CheckBox focus border appear when I have programmatically focused the CheckBox?

推荐答案

边框有意仅在您通过键盘(Tab键)导航时显示。有关此主题的 MSDN页面有详细信息:

The border is intentionally only shown if you are navigating by the keyboard (Tab key). The MSDN page on this topic has further details:


只有在
焦点动作由
键盘启动时,焦点视觉样式才会起作用。任何鼠标操作或
程序化焦点更改会禁用焦点视觉样式的
模式。

如果你想显示一个边框,你可以使用IsFocused-属性上的一个触发器做一些视觉变化(虽然你不能用这个设置边框),或者如果你真的想要一个边框,你必须创建自己的ControlTemplate。

If you want to show a border, you could use a Trigger on the IsFocused- Property to do some visual changes (although you can't set the border with this) or if you actually want a border, you would have to create your own ControlTemplate.

还有一个

There is also a thread here on SO on a somewhat related topic where the suggestion is to simulate a key press, but I would suggest not to use this solution for your problem.

这篇关于如何使CheckBox的焦点边框出现时调用CheckBox.Focus()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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