C# 如何以编程方式显示textbox的键盘?
我在windows phone页面上有一个文本框,我想在页面加载后立即显示键盘 当我导航到此页面时,是否有任何方法使此文本框已聚焦 我考虑过使用C# 如何以编程方式显示textbox的键盘?,c#,silverlight,windows-phone-7,C#,Silverlight,Windows Phone 7,我在windows phone页面上有一个文本框,我想在页面加载后立即显示键盘 当我导航到此页面时,是否有任何方法使此文本框已聚焦 我考虑过使用Guide.BeginShowKeyboardInput(),但我认为在silverlight中这不是一个好的解决方案。覆盖页面的方法 protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); // Set focus to the
Guide.BeginShowKeyboardInput()
,但我认为在silverlight中这不是一个好的解决方案。覆盖页面的方法
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
// Set focus to the TextBox, this will pop up the
// virtual keyboard
myTextBox.Focus();
}
是的,我不会手动显示键盘。对于那些拥有带有物理键盘的设备的人来说,这可能是一件麻烦事。在页面的load事件中,您可以在要选择的文本框上调用Focus方法。键盘应根据需要自动显示
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
txtLongitude.Focus();
}
如果在
on navigated to
事件中使用调度程序,则可以通过调度程序调用textBox.Focus()
:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (e.NavigationMode != NavigationMode.Back)
{
Dispatcher.InvokeAsync(() => ShowKeyboard());
}
}
private void ShowKeyboard()
{
textBox.Focus();
}
此处的if
语句确保仅当页面未从后退按钮导航到时才显示键盘。将页面加载到文本框后提供焦点是否会自动显示键盘?