【发布时间】:2018-07-25 09:52:04
【问题描述】:
我刚刚开始使用 Xamarin.Forms 进行编程,恐怕我可能需要一些帮助。我对标准 XAML 非常方便,但 Xamarin.Forms 有一些限制和一些腼腆的小警告。
所以问题是:如何在同一个视图中实现混合的固定和可滚动元素?就像,我希望下面的按钮固定在底部,然后是内容区域的其余部分,我希望是可滚动的。
有没有办法做到这一点?
-- 更新--
好的……
这是我的代码,顶部和底部渲染正确,而 ScrollView 区域根本不渲染……完全空白……?
<ContentPage.Content>
<Grid BackgroundColor="{StaticResource BackgroundGray}">
<Grid.RowDefinitions>
<RowDefinition Height="96" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackLayout Grid.Row="0" HeightRequest="96" BackgroundColor="White" VerticalOptions="Center">
<Image Source="biodatix.jpg" VerticalOptions="Center" HeightRequest="48" Margin="4,8,4,4" />
<Label FontFamily="Arial" FontSize="20" TextColor="{StaticResource AppLightOrange}" HorizontalTextAlignment="Center">BioDatix</Label>
</StackLayout>
<ScrollView Grid.Row="1" VerticalOptions="FillAndExpand">
<Entry x:Name="Username" Placeholder="Email Address" Text="{Binding User.Email}" FontSize="Small" />
<Label x:Name="reqemail" Text="Please enter an email address" IsVisible="False" FontSize="Micro" TextColor="Red"/>
<Entry x:Name="RetypeUsername" Placeholder="Retype Email Address" FontSize="Small" />
<Label x:Name="reqemailverify" Text="Please confirm your email address" IsVisible="False" FontSize="Micro" TextColor="Red"/>
<Entry IsPassword="True" Placeholder="Password" x:Name="Password" Text="{Binding User.Password}" FontSize="Small" />
<Label x:Name="reqpass" Text="Please enter a password" IsVisible="False" FontSize="Micro" TextColor="Red"/>
<Entry x:Name="FirstName" Placeholder="First Name" Text="{Binding User.FirstName}" FontSize="Small" />
<Label x:Name="reqfirstname" Text="Please enter your first name" IsVisible="False" FontSize="Micro" TextColor="Red"/>
<Entry x:Name="LastName" Placeholder="Last Name" Text="{Binding User.LastName}" FontSize="Small" />
<Label x:Name="reqlastname" Text="Please enter your last name" IsVisible="False" FontSize="Micro" TextColor="Red"/>
<StackLayout Orientation="Horizontal" Margin="4">
<Label x:Name="lblUseMetric" Margin="2">Use Metric System</Label>
<Switch x:Name="UseMetric" IsToggled="{Binding User.Metric}"></Switch>
</StackLayout>
<Entry x:Name="UserHeight" Placeholder="Height" Text="{Binding User.Height}" FontSize="Small" />
<Label x:Name="reqheight" Text="Please enter your height" IsVisible="False" FontSize="Micro" TextColor="Red"/>
<Entry x:Name="UserWeight" Placeholder="Weight" Text="{Binding User.Weight}" FontSize="Small" />
<Label x:Name="reqweight" Text="Please enter your weight" IsVisible="False" FontSize="Micro" TextColor="Red"/>
<StackLayout Orientation="Horizontal" Margin="4">
<Label x:Name="lblWearSide" Margin="2">Wears Right</Label>
<Switch x:Name="WearSide" IsToggled="{Binding User.WearSide}"></Switch>
</StackLayout>
<Label x:Name="lblError" Text="" IsVisible="False" FontSize="Default" TextColor="Red"/>
</ScrollView>
<Button x:Name="RegisterBtn" Clicked="RegisterBtn_Clicked" WidthRequest="200" HorizontalOptions="Center" BackgroundColor="{StaticResource AppGreen}" Grid.Row="2" Text="Sign In" Margin="4" />
<Button x:Name="CancelBtn" Clicked="CancelBtn_Clicked" WidthRequest="200" HorizontalOptions="Center" BackgroundColor="{StaticResource AppGreen}" Grid.Row="3" Text="Help Signing In" Margin="4" />
</Grid>
</ContentPage.Content>
【问题讨论】:
-
是的,您可以这样做。例如,您可以将一个可滚动元素(例如 ListView)和一个 StackLayout 嵌套在另一个 StackLayout 中的底部按钮。
-
或者,您可以使用两行网格并将可滚动元素放在顶行
-
ScrollView 只能有一个孩子。将子元素包裹在堆栈布局中
-
其实……这行不通……因为 ScrollView 内部没有任何东西是可见的。它是空白的。为什么?
标签: c# xaml xamarin.forms scrollview