如果我删除了滚动视图,并且网格与其他元素是内联的,那么一切都将按预期显示。
我使用的是xamarin.forms 2.5.0,但也可以用最新的3.1.0来复制它,这在UWP、Android和iOS中都可以看到。
<?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:XamarinScrollView"
x:Name="TheMainPage"
x:Class="XamarinScrollView.MainPage">
<StackLayout BindingContext="{x:Reference TheMainPage}">
<ActivityIndicator IsRunning="{Binding IsBusy}" IsVisible="{Binding IsBusy}" />
<Label Text="{Binding StringValue}" LineBreakMode="WordWrap" />
<Label Text="{Binding StringValue}" />
<Label Text="{Binding StringValue}" LineBreakMode="WordWrap" />
<Label Text="{Binding StringValue, StringFormat='String Value: {0}'}" IsVisible="{Binding HasStringValue}" />
<Label Text="{Binding StringValue, StringFormat='String Value: {0}'}" />
<Label Text="{Binding StringValue, StringFormat='String Value: {0}'}" />
<BoxView HeightRequest="2">
<BoxView.Color>
<OnPlatform x:TypeArguments="Color">
<On Platform="Android">White</On>
<On Platform="iOS">Black</On>
<On Platform="UWP">Black</On>
</OnPlatform>
</BoxView.Color>
</BoxView>
<ScrollView Orientation="Horizontal">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Text="{Binding DateValue, StringFormat='Date Value: {0:g}'}" />
<Label Grid.Row="1" Grid.Column="0" Text="{Binding DateValue, StringFormat='Date Value: {0:g}'}" />
<Label Grid.Row="2" Grid.Column="0" Text="{Binding StringValue, StringFormat='String Value: {0}'}" />
<Label Grid.Row="0" Grid.Column="1" Text="{Binding DateValue, StringFormat='Date Value: {0:g}'}" />
<Label Grid.Row="1" Grid.Column="1" Text="{Binding DateValue, StringFormat='Date Value: {0:g}'}" />
<Label Grid.Row="2" Grid.Column="1" Text="{Binding DateValue, StringFormat='Date Value: {0:g}'}" />
</Grid>
</ScrollView>
<Frame Margin="2">
<Frame.BorderColor>
<OnPlatform x:TypeArguments="Color">
<On Platform="Android">White</On>
<On Platform="iOS">Black</On>
<On Platform="UWP">Black</On>
</OnPlatform>
</Frame.BorderColor>
<StackLayout Padding="0,0,0,20">
<Label Text="String Value" />
<Label Text="{Binding StringValue}" LineBreakMode="WordWrap" />
</StackLayout>
</Frame>
<Frame Margin="2">
<Frame.BorderColor>
<OnPlatform x:TypeArguments="Color">
<On Platform="Android">White</On>
<On Platform="iOS">Black</On>
<On Platform="UWP">Black</On>
</OnPlatform>
</Frame.BorderColor>
<ListView ItemsSource="{Binding ListItems}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Margin="0,0,0,10">
<Label Text="{Binding StringValue1}" />
<Label Text="{Binding StringValue2}" />
<Label Text="{Binding StringValue3}" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Frame>
</StackLayout>
</ContentPage>
代码隐藏
using System;
using System.Collections.Generic;
using Xamarin.Forms;
namespace XamarinScrollView {
public partial class MainPage : ContentPage {
public MainPage() {
InitializeComponent();
}
public string StringValue => "This is a string";
public DateTime DateValue => DateTime.Now;
public bool HasStringValue => true;
private readonly List<ListItem> listItems = new List<ListItem> {
new ListItem(),
};
public IEnumerable<ListItem> ListItems => listItems;
}
public sealed class ListItem {
public string StringValue1 => "1. This is a string";
public string StringValue2 => "2. This is a string";
public string StringValue3 => "3. This is a string";
}
}