checkbox 点击搜索失去焦点,如何使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.

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

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

解决方案

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

Focus visual styles act only when the

focus action was initiated by the

keyboard. Any mouse action or

programmatic focus change disables the

mode for focus visual styles.

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值