[英]Software Keyboard Dissapears from screen when PasswordBox given focus
我在页面上设置了一个PasswordBox,试图将其设置为导航到该页面时自动具有焦点。
我遇到的问题是,当我以编程方式使其聚焦时,它可以接受聚焦,但是键盘消失了。
这会导致出现问题,因为用户必须单击“密码框”,然后再使用该控件。
我试过将此代码添加到页面的Loaded事件,ContentGrid.Loaded,OnNavigatedTo中,并且它们都产生相同的结果。
我尝试设置页面的TabIndex / IsTabStop以及控件本身,但是它似乎不起作用。 密码框是唯一具有TabIndex的项目。
<PasswordBox x:Name="pwbAnswer" Style="{StaticResource PasswordBoxStyle}" VerticalAlignment="Top" Grid.Row="3"
PasswordChanged="pwbAnswer_PasswordChanged" KeyUp="pwbAnswer_KeyUp" TabIndex="1" IsTabStop="True" />
private void ContentGrid_Loaded(object sender, RoutedEventArgs e)
{
this.IsTabStop = true;
pwbAnswer.Focus();
}
您必须使用PasswordBox的Loaded事件。 我有同样的问题。 然后,如果您附加了该加载事件,则可以将焦点设置为发件人,也就是PasswordBox本身。
<PasswordBox x:Name="pwbAnswer" Style="{StaticResource PasswordBoxStyle}" VerticalAlignment="Top" Grid.Row="3"
Loaded="PasswordBox_Loaded" PasswordChanged="pwbAnswer_PasswordChanged" KeyUp="pwbAnswer_KeyUp" TabIndex="1" IsTabStop="True" />
private void PasswordBox_Loaded(object sender, RoutedEventArgs e)
{
PasswordBox box = sender as PasswordBox;
box.Focus();
}
或者您可以将解决方法与LayoutUpdated事件一起使用。
<Page .... LayoutUpdated="ContentGrid_LayoutUpdated">
<PasswordBox x:Name="pwbAnswer" Style="{StaticResource PasswordBoxStyle}" VerticalAlignment="Top" Grid.Row="3"
KeyUp="pwbAnswer_KeyUp" TabIndex="1" IsTabStop="True" />
private void ContentGrid_LayoutUpdated(object sender, RoutedEventArgs e)
{
this.IsTabStop = true;
pwbAnswer.Focus();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.