Xamarin Forms,每次击键后在输入时关闭键盘

时间:2018-11-14 11:00:32

标签: c# xamarin xamarin.forms

在某些“输入”字段中,键盘在每次击键时都会关闭。从Xamarin Forms 3.0开始引入了此问题。因此在2.5中不会发生此问题。

此问题仅出现在iOS中,而不是Android(afaik)。

您可以使用以下测试代码复制它:

Page.xaml:

<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:TestEntryKeyboard" x:Class="TestEntryKeyboard.MainPage">
    <StackLayout x:Name="stackTest">
    </StackLayout>
</ContentPage>

Page.xaml.cs:

public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();

        var table = new TableView()
        {
            HorizontalOptions = LayoutOptions.FillAndExpand,
            VerticalOptions = LayoutOptions.FillAndExpand,
            Intent = TableIntent.Form,
            HasUnevenRows = true,
            Root = new TableRoot()
        };

        stackTest.Children.Clear();
        stackTest.Children.Add(table);

        TableSection section = new TableSection("");
        table.Root.Add(section);

        for (int index = 1; index < 20; index++)
        {
            var viewCell = new ViewCell();
            var stack = new StackLayout();
            viewCell.View = stack;

            var label = new Label() { Text = $"Entry {index}:" };
            stack.Children.Add(label);

            var entry = new Entry() { };
            stack.Children.Add(entry);

            section.Add(viewCell);
        }

    }
}

在iPhone SE屏幕尺寸上,至少在我的测试场景中,问题出现在第10和11号输入字段中。如果您使用屏幕尺寸更大的其他iPhone(例如XR),则会在其他Entry(输入)字段中出现问题,例如15和16。

因此,如果您对此进行测试,请确保在多个Entry控件中进行测试,因为很多控件都可以工作,而只有少数控件不能工作。

我的猜测是,它与单元重用有关。

NB:我在这里发布的测试代码就是我所使用的全部。所以我不使用事件处理程序。

0 个答案:

没有答案
相关问题