Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 752
Dmitri Nesteruk Avatar asked Jan 28 '09 10:01

Dmitri Nesteruk


1 Answers

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.

like image 200
Bubblewrap Avatar answered Nov 13 '22 07:11

Bubblewrap