简体   繁体   中英

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. 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.

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. 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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