Xamarin 表单-切换到其他页面时为什么不隐藏键盘?

Xamarin 表单-切换到其他页面时为什么不隐藏键盘?,xamarin,xamarin.forms,Xamarin,Xamarin.forms,页面没有输入字段只有一个标签,但切换到此页面时键盘不会消失。这是正常的行为吗?如何使键盘在新页面上不打开?谢谢 第一页xaml <ContentPage.Content> <StackLayout x:Name="stackLayout2"> <Label x:Name="code_label" HorizontalOptions="CenterAndExpand" Font="Bold, Micro" TextColor="black" F

页面没有输入字段只有一个标签,但切换到此页面时键盘不会消失。这是正常的行为吗?如何使键盘在新页面上不打开?谢谢

第一页xaml

<ContentPage.Content>
    <StackLayout x:Name="stackLayout2">
        <Label x:Name="code_label" HorizontalOptions="CenterAndExpand" Font="Bold, Micro" TextColor="black" FontSize="19" Margin="15, 30, 15, 0" />
        <Entry x:Name="code_field" TextChanged="CodeFieldTextChanged"  Keyboard="Telephone" MaxLength="4" Margin="15, 30, 15, 0" />
    </StackLayout>
</ContentPage.Content>
主页xaml

<ContentPage.Content>
    <StackLayout>
        <Label Text="Authorization ok!"
            VerticalOptions="CenterAndExpand" 
            HorizontalOptions="CenterAndExpand" />
    </StackLayout>
</ContentPage.Content>

如果Application.Current.MainPage=新主页;被Application.Current.MainPage=新导航页面新主页替换;然后键盘消失了,但在第一种情况下,键盘保持不变。这个问题似乎只发生在Android上。现在发生的情况是,您在更改页面时从未在电话键盘上打过绿色返回复选标记,因此操作系统不会关闭键盘,因此您必须手动关闭键盘。试试这个:

private void CodeFieldTextChanged(object sender, TextChangedEventArgs args)
{
    if (args.NewTextValue == "3333")
    {
        // Add the following two lines to dismiss the keyboard
        Entry entry = sender as Entry;
        entry.Unfocus();
        Application.Current.MainPage = new HomePage();
    }
}

您能否提供一个MCVE最小、完整、可验证的示例?我添加了代码示例
private void CodeFieldTextChanged(object sender, TextChangedEventArgs args)
{
    if (args.NewTextValue == "3333")
    {
        // Add the following two lines to dismiss the keyboard
        Entry entry = sender as Entry;
        entry.Unfocus();
        Application.Current.MainPage = new HomePage();
    }
}