In our Windows Store app we have a textbox, and when the application starts this textbox always get focus. In a desktop scenario that's no problem, but on a tablet device this focus will directly open the onscreen keyboard which is not a scenario that we want.
We tried to set the focus on another control programmatic with the .Focus(FocusState) method, but somehow the focus is set back to the textbox. We have both set the focus in the LoadState or the OnNavigatedTo method.
Only when we have timer we have set the focus succesfully to another control. Anyone has ideas how to set the focus to another control, or preferably set not focus at all to an control?
IsTabStop="true" didn't work for me. My solution is to call UpdateLayout() of the scrollViewer before setting the focus on the TextBox:
scrollViewer.UpdateLayout();
textBox.Focus(Windows.UI.Xaml.FocusState.Programmatic);
If you don't like accepted answer with the
ScrollViewer
you can also do this to remove the focus:Normally you can set the Focus on any element by
TextBox.Focus()
. However I discovered the same behaviors (autofocus on start) when you place your TextBox inside a ScrollViewer or a FlyOut. Then you have to set the IsTabStop on the parent-element: