Search code examples
c#silverlightwindows-phone-7

Set focus to TextBox


In my WindowsPhone application I have a Text Box that needs to receive focus at a given time. What I've tried so far:

textBox1.Focus();

textBox1.UpdateLayout();
textBox1.Focus();

textBox1.IsTabStop = true;
textBox1.UpdateLayout();
textBox1.Focus();

textBox1.IsTabStop = true;
textBox1.Focus();

Nothing seems to work. In the Emulator, when the Focus() method is called, the keyboard starts to rise, but then crashes back. The TextBox has IsTabStop set to true in the properties.


Solution

  • This seems to be a Silverlight bug. I've used the TextChanged event on the TextBox, and set the Focus() in there. Kind of an ugly workaround, but it worked for me. If anybody has another solution, please post.