开发者

Hold focus on textbox that do something in the textchanged event

I have a problem: I handled textchanged event of a textbox. When the event fires I do something in the UI (li开发者_开发知识库ke add a row in a listbox) and the textbox lost the KeyboardFocus. How can I hold the KeyboardFocus on that textbox?

Thanks


Write the following

this.MyTextBox.Focus()

at the end of your handler. or make your UIElement.Focusable = false. it should help.


You can set the focus back on the textbox in the code-behind where you handle the event using textBoxName.Focus();

Focus can be set in the XAML using FocusManager.FocusedElement="{Binding ElementName=textBoxName}"

but if the focus is lost when you add a new element then you may need to use code-behind to reset it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜