简体   繁体   English

在WPF文本框中设置焦点

[英]Set focus in WPF textbox

I am writing a control in WPF that draws a shape on a form and then draws dimensions of this shape. 我正在WPF中编写控件,该控件先在窗体上绘制形状,然后绘制该形状的尺寸。 These dimensions are editable so they are shown in a text box. 这些尺寸是可编辑的,因此它们显示在文本框中。 When the user changes a dimension in a text box the shape is updated. 当用户在文本框中更改尺寸时,形状将更新。

I am updating the shape when the textbox showing the dimension loses focus ie as soon as the text box loses the focus the shape and all the dimensions are redrawn. 当显示尺寸标注的文本框失去焦点时,即在文本框失去焦点时,我将更新形状,并重新绘制所有尺寸。 A text box loses focus in one of two ways - either when user presses tab key or when user clicks in another control outside the text box. 文本框会以两种方式之一失去焦点-用户按下Tab键或用户单击文本框外的另一个控件时。

My problem is that when user presses tab key or clicks somewhere else outside the text box the whole control is redrawn and the focus is not set to the next control where it should be. 我的问题是,当用户按Tab键或在文本框外的其他位置单击时,整个控件将被重绘,并且焦点没有设置为下一个控件应位于的位置。 This is really annoying because tabs stop working altogether and to set a focus using mouse the user has to click twice. 这确实很烦人,因为选项卡完全停止工作,并且要使用鼠标设置焦点,用户必须单击两次。 Is there a way around this? 有没有解决的办法?

An image of my control is shown below 我的控件的图像如下所示

alt text http://img223.imageshack.us/img223/9496/cavity.png 替代文字http://img223.imageshack.us/img223/9496/cavity.png

看来您想自己在此窗口中管理制表符顺序并执行此操作,我认为您可以在这些编辑字段上订阅GotKeyboardFocus和LostKeyboardFocus事件,然后在不满意的情况下将焦点移到适当的位置重点放在哪里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM