当软键盘存在时,Xamarin.Forms登录表单需要双击提交表单

时间:2017-02-08 21:00:11

标签: xamarin xamarin.forms

我的登录屏幕表现不如我所料,第一次点击登录按钮只会解除软键盘,按钮不会触发任何事件。 因此,要登录,用户必须再次申请登录按钮。

这对我来说似乎不对,但是我试图弄清楚这是否是预期的行为,也许我应该手动关闭键盘。或者,如果这应该被解雇并通过表格传递事件。

这是一个包含问题示例的回购:https://github.com/GiusepeCasagrande/ScrollLoginBug

2 个答案:

答案 0 :(得分:1)

This has been answered in Xamarin Forum. This is a bug in Xamarin Button's focus/unfocus event in iOS. Bug Report can be found in: https://bugzilla.xamarin.com/show_bug.cgi?id=57377

The Work-around solution is using "TapGestureRecognizer" instead of Button Click. Replace you Button with code below will fix your problem:

data.frame

https://forums.xamarin.com/discussion/69196/xamarin-forms-ios-button-click-event-is-not-firing-when-the-keyboard-is-open

答案 1 :(得分:0)

SignIn按钮被键盘阻止。用户点击SignIn按钮的唯一方法是关闭键盘,然后点击按钮。

如果您描述了您尝试实施的用户界面,我将编辑我的答案并提供一些代码。

enter image description here enter image description here

更新

用户在输入密码后点按两次以点按“登录”按钮的原因是因为您Grid内嵌有StackLayout。删除Grid后,用户可以

原始ScrollLoginTestPage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="ScrollLoginTest.ScrollLoginTestPage"
             xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:ScrollLoginTest">
    <ContentPage.Content BackgroundColor="{DynamicResource defaultBackgroundColor}">
        <ScrollView x:Name="LoginScrollView" BackgroundColor="{DynamicResource defaultBackgroundColor}">
            <StackLayout Orientation="Vertical" Padding="40">
                <Grid VerticalOptions="CenterAndExpand">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="60" />
                        <RowDefinition Height="60" />
                        <RowDefinition Height="60" />
                    </Grid.RowDefinitions>
                    <Entry x:Name="Server"
                           Grid.Row="0"
                           Grid.Column="0"
                           VerticalOptions="End"
                           AutomationId="LoginView_Server"
                           Keyboard="Url"
                           Placeholder="Server"
                           Style="{DynamicResource regularEntry}" />
                    <Entry x:Name="UserName"
                           Grid.Row="1"
                           Grid.Column="0"
                           VerticalOptions="End"
                           AutomationId="LoginView_UserName"
                           Keyboard="Email"
                           Placeholder="UserName"
                           Style="{DynamicResource regularEntry}" />
                    <Entry x:Name="Password"
                           Grid.Row="2"
                           Grid.Column="0"
                           VerticalOptions="End"
                           AutomationId="LoginView_Password"
                           IsPassword="true"
                           Placeholder="Password"
                           Style="{DynamicResource regularEntry}" />
                </Grid>
                <Grid VerticalOptions="EndAndExpand">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width=".20*" />
                        <ColumnDefinition Width=".6*" />
                        <ColumnDefinition Width=".20*" />
                    </Grid.ColumnDefinitions>
                    <Button x:Name="LoginButton"
                            Grid.Row="0"
                            Grid.Column="1"
                            AutomationId="LoginView_SignIn"
                            Style="{DynamicResource blueButton}"
                            Text="SignIn" />
                </Grid>
            </StackLayout>
        </ScrollView>
    </ContentPage.Content>
</ContentPage>

更新了ScrollLoginTestPage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="ScrollLoginTest.ScrollLoginTestPage"
             xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:ScrollLoginTest;assembly=ScrollLoginTest">
    <ContentPage.Content BackgroundColor="{DynamicResource defaultBackgroundColor}">
        <ScrollView x:Name="LoginScrollView" BackgroundColor="{DynamicResource defaultBackgroundColor}">
            <StackLayout Padding="40">
                    <Entry x:Name="Server"
                           VerticalOptions="End"
                           AutomationId="LoginView_Server"
                           Keyboard="Url"
                           Placeholder="Server"
                           Style="{DynamicResource regularEntry}" />
                    <Entry x:Name="UserName"
                           VerticalOptions="End"
                           AutomationId="LoginView_UserName"
                           Keyboard="Email"
                           Placeholder="UserName"
                           Style="{DynamicResource regularEntry}" />
                    <Entry x:Name="Password"
                           VerticalOptions="End"
                           AutomationId="LoginView_Password"
                           IsPassword="true"
                           Placeholder="Password"
                           Style="{DynamicResource regularEntry}" />
                 <Button x:Name="LoginButton"
                            AutomationId="LoginView_SignIn"
                            Style="{DynamicResource blueButton}"
                            Text="SignIn" />
            </StackLayout>
        </ScrollView>
    </ContentPage.Content>
</ContentPage>

我在GitHub中为您的解决方案打开了一个Pull Request:https://github.com/GiusepeCasagrande/ScrollLoginBug/pull/1