In Windows 8, when a page is navigated, I need to put the focus to a specific TextBox.
I used:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
myControl.Focus(Windows.UI.Xaml.FocusState.Keyboard);
}
But it does not work. However, if I call myControl.Focus(Windows.UI.Xaml.FocusState.Keyboard);
from a button click event, it works fine.
How can I set the focus to a TextBox when the page is loaded?
Try calling myControl.Focus(Windows.UI.Xaml.FocusState.Keyboard);
with this.Dispatcher
A code sample:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
Dispatcher.RunAsync(
CoreDispatcherPriority.Normal,
() => myControl.Focus(FocusState.Keyboard));
}
Try this:
myControl.Focus(Windows.UI.Xaml.FocusState.Keyboard);
and set this control(mycontrol)
as the first control in your XAML code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With