Calling Select () in a WPF text field does nothing

I use WPF TextBox and I call the Select() method to make a selection. Unfortunately, it does not work unless I select something manually first. Can someone tell me why this is happening?

+6
user-interface c # wpf
source share
1 answer

Is your text block focused when calling the Select method?

The selection will not be displayed if it has no focus, but the general way for the text field to get focus is to click on it ... which deselects the text. This behavior may give the impression that it does not work.

A call to TextBox.Focus () after (or before) a call to Select () should fix it.

+9
source share

All Articles