Some time you want to make your app more user friendly by automatically focus on specify control for example search text box so that when user open the page, they can start typing the keyword they want to search rather than click on the search text box first then only start typing.
I try to use TextBox.Focus() in OnNavigatedTo, but it nothing happen. So I try to use the same method use in Silverlight by creating a DispatcherTimer and delay the focus by 0.5 second. Well, this method work out in Windows Store App. If you are interested, below are the code.
// timer to create initial focus on control DispatcherTimer initialFocusDispatcherTimer = new DispatcherTimer(); initialFocusDispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 500); initialFocusDispatcherTimer.Tick += (tickSender, tickEvent) => { initialFocusDispatcherTimer.Stop(); // focus on search bar SearchTextBox.Focus(Windows.UI.Xaml.FocusState.Keyboard); }; initialFocusDispatcherTimer.Start();
by Ooi Keng Siang via Ooiks’s Blog