Scrollview在Xamarin Forms中不起作用

时间:2019-01-22 13:17:28

标签: xamarin.forms scrollview

我的xamarin表单应用程序中具有以下布局:

<?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:telerikInput="clr-namespace:Telerik.XamarinForms.Input;assembly=Telerik.XamarinForms.Input"
             xmlns:telerikPrimitives="clr-namespace:Telerik.XamarinForms.Primitives;assembly=Telerik.XamarinForms.Primitives"
             x:Class="DMGMobile.UserDetailPage">
    <ContentPage.ToolbarItems>
        <ToolbarItem Name="Save" Icon="settings.png" Clicked="Save"></ToolbarItem>
    </ContentPage.ToolbarItems>

    <ContentPage.Content>
        <ScrollView 
            Orientation="Vertical" 
            VerticalScrollBarVisibility="Always"
            VerticalOptions="FillAndExpand">
            <StackLayout
                VerticalOptions="FillAndExpand"
                Padding="10,0,10,0">

                <Label 
                    Text="Name"/>
                <telerikInput:RadEntry 
                    x:Name="User_Name"
                    BackgroundColor="White" 
                    WatermarkText="Name"
                    TextColor="Black"
                    WatermarkTextColor="#C0C0C0">
                    <telerikInput:RadEntry.Padding>
                        <OnPlatform x:TypeArguments="Thickness">
                            <On Platform="Android,UWP" Value="10,10,0,10" />
                            <On Platform="iOS" Value="10,10,0,20" />
                        </OnPlatform>
                    </telerikInput:RadEntry.Padding>
                    <telerikInput:RadEntry.BorderStyle>
                        <telerikInput:BorderStyle 
                            CornerRadius="8"
                            BorderColor="#257cc1"
                            BorderThickness="1" />
                    </telerikInput:RadEntry.BorderStyle>
                </telerikInput:RadEntry>

                <Label 
                    Text="Surname"/>
                <telerikInput:RadEntry 
                    x:Name="User_Vorname"
                    BackgroundColor="White" 
                    WatermarkText="Surname"
                    TextColor="Black"
                    WatermarkTextColor="#C0C0C0">
                    <telerikInput:RadEntry.Padding>
                        <OnPlatform x:TypeArguments="Thickness">
                            <On Platform="Android,UWP" Value="10,10,0,10" />
                            <On Platform="iOS" Value="10,10,0,20" />
                        </OnPlatform>
                    </telerikInput:RadEntry.Padding>
                    <telerikInput:RadEntry.BorderStyle>
                        <telerikInput:BorderStyle 
                        CornerRadius="8"
                        BorderColor="#257cc1"
                        BorderThickness="1" />
                    </telerikInput:RadEntry.BorderStyle>
                </telerikInput:RadEntry>

                <Label 
                    Text="Login"/>
                <telerikInput:RadEntry 
                    x:Name="User_Login"
                    BackgroundColor="White" 
                    WatermarkText="Login"
                    TextColor="Black"
                    WatermarkTextColor="#C0C0C0"
                    TextChanged="User_Login_TextChanged">
                    <telerikInput:RadEntry.Padding>
                        <OnPlatform x:TypeArguments="Thickness">
                            <On Platform="Android,UWP" Value="10,10,0,10" />
                            <On Platform="iOS" Value="10,10,0,20" />
                        </OnPlatform>
                    </telerikInput:RadEntry.Padding>
                    <telerikInput:RadEntry.BorderStyle>
                        <telerikInput:BorderStyle 
                        CornerRadius="8"
                        BorderColor="#257cc1"
                        BorderThickness="1" />
                    </telerikInput:RadEntry.BorderStyle>
                </telerikInput:RadEntry>

                <Label 
                    Text="Pass"/>
                <telerikInput:RadEntry 
                    x:Name="User_Password"
                    BackgroundColor="Transparent" 
                    WatermarkText="Pass"
                    TextColor="Black"
                    WatermarkTextColor="#C0C0C0"
                    TextChanged="User_Login_TextChanged">
                    <telerikInput:RadEntry.Padding>
                        <OnPlatform x:TypeArguments="Thickness">
                            <On Platform="Android,UWP" Value="10,10,0,10" />
                            <On Platform="iOS" Value="10,10,0,20" />
                        </OnPlatform>
                    </telerikInput:RadEntry.Padding>
                    <telerikInput:RadEntry.BorderStyle>
                        <telerikInput:BorderStyle 
                        CornerRadius="8"
                        BorderColor="#257cc1"
                        BorderThickness="1" />
                    </telerikInput:RadEntry.BorderStyle>
                </telerikInput:RadEntry>

                <telerikPrimitives:RadCheckBox 
                    x:Name="User_IsAdmin" />
                <Label 
                    Text="Is admin}"/>

            </StackLayout>
        </ScrollView>
    </ContentPage.Content>
</ContentPage>

问题是ScrollView无法正常工作。尽管VerticalScrollBarVisibility设置为Always,但我什至看不到垂直滚动条。 没有键盘的情况下,该页面看起来不错,但是如果显示了键盘,则位于页面底部的某些输入将被隐藏,而我无法滚动以到达它们。

我在这里想念一些令人讨厌的东西吗?

1 个答案:

答案 0 :(得分:0)

如果您使用的是Android,则可以在MainActivity中的LoadApplication之后添加此代码:

Xamarin.Forms.Application.Current.On<Xamarin.Forms.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);