Skip to main content

Microsoft Silverlight

Setting TextBox.SelectedText propertyRSS Feed

(0)

Bigsby
Bigsby

Member

Member

262 points

81 Posts

Setting TextBox.SelectedText property

I already refered to this in another thread but I think this should have its own proper care.

What happens is that when TextBox.SelectedText property is set the rest of the text in the TextBox is cleared and the only remaining text is the text set to be the SelectedText and even so not selected.

Some thing like this:

 

TextBox tb = new TextBox;

tb.Text = "This is the text in the TextBox";

tb.SelectedText = "Selected Text";

 

After this code tb.Text whoud be only "Selected Text" with no selection.

Bigsby
Bigsby

Member

Member

262 points

81 Posts

Re: Setting TextBox.SelectedText property

No news about this?

Sergey Volk MSFT
Sergey V...

Participant

Participant

788 points

98 Posts

Microsoft

Re: Setting TextBox.SelectedText property

I don't think it's a bug. I have just tried this:

TextBox tb = new TextBox();tb.Text = "This is the text in the TextBox";

LayoutRoot.Children.Add(tb);

tb.SelectionStart = 12;

tb.SelectionLength = 4;

tb.SelectedText = "abc";

And it works as expected (textbox contains "This is the abc in the TextBox"). Have you tried setting SelectionStart / SelectionLength before setting SelectedText?

If this answers your question, please click on "Mark as Answer" on this post.
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities