4

As titled, and basically I wanted to do the same thing as this for WPF but in Silverlight instead.

But in my TextBox.LostFocus event, there is no e.Handled. And I also tried to use VisualStateManger.GoToState to Focused State:

        VisualStateManager.GoToState(TextBox1, "Focused", false);
        TextBox1.SelectionStart = 0;
        TextBox1.SelectionLength = 3;
        TextBox1.SelectionForeground = new SolidColorBrush(Colors.Orange);

But it doesn't work either.

Is there any workaround?

Community
  • 1
  • 1
King Chan
  • 4,212
  • 10
  • 46
  • 78

1 Answers1

0

The following code will select all on focus.

TextBox1.Select(0, TextBox1.Text.Length);

Perhaps using this method to set selection. If the selection doesn't persist, try storing your caret position and length in a temporary variable (within a custom textbox class).

Muster Station
  • 504
  • 2
  • 9