TextBox光标不闪烁 [英] TextBox Cursor is NOT blinking

查看:1028
本文介绍了TextBox光标不闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在GenerateEditingElement中,我创建了一个自定义文本框控件(带有一个额外的按钮)



我得到的最接近的是插入符号被显示,但不是闪烁,我需要一个



任何其他东西(绑定,...)都可以正常工作


解决方案

由于插入符号被显示,而不是闪烁,我猜你的控件有逻辑聚焦,



myControl.Focus (); 将给予控件逻辑焦点,但它不会响应键盘事件,因为它没有键盘焦点。要给一个元素KeyboardFocus,请使用

  Keyboard.Focus(myControl); 

这是因为WPF允许您定义多个焦点范围,每个范围都可以有自己的焦点元素,但是在整个应用程序中只有一个控件可以有Keyboard Focus


I have a WPF datagrid (4.0) with a custom column (derived from DataGridTextColumn).

In GenerateEditingElement I create a custom textbox control (with an additional button) and like to set the cursor into it so that the user can directly start editing.

The closest I get is that the caret is shown but is not blinking and I need an additional click to start editing.

All other stuff (binding, ...) is working nicely

Any ideas?

解决方案

Since the caret is shown, but not blinking, then I am guessing your control has Logical Focus, but not Keyboard Focus.

How are you setting the control as Focused?

myControl.Focus(); will give the control logical focus, but it won't respond to keyboard events because it doesn't have Keyboard focus. To give an element KeyboardFocus, use

Keyboard.Focus(myControl);

This is because WPF allows you to define multiple Focus Scopes, and each scope can have it's own focused element, however only one control in the entire application can have Keyboard Focus

这篇关于TextBox光标不闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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