Calling Select() on WPF text box doesn't do anything

妖精的绣舞 提交于 2021-02-07 12:24:15

问题


I'm using a WPF TextBox, and I'm calling the Select() method to make a selection. Unfortunately, it doesn't seem to work unless I select something manually first. Can someone suggest as to why it happens?


回答1:


Does your textbox have focus when you call the Select method?

The selection will not show unless it has focus, but the common way for the textbox to get focus is by clicking on it...which deselects the text. This behaviour could give the impression that it's not working.

Calling TextBox.Focus() after (or before) calling Select() should fix it.



来源:https://stackoverflow.com/questions/487141/calling-select-on-wpf-text-box-doesnt-do-anything

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!