C# 元素自动栅格。行和栅格。列
我有一个MainPage.xaml代码:C# 元素自动栅格。行和栅格。列,c#,xamarin,xamarin.forms,grid,C#,Xamarin,Xamarin.forms,Grid,我有一个MainPage.xaml代码: <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="GridTest.MainPage"> <ScrollView>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="GridTest.MainPage">
<ScrollView>
<Grid x:Name="test" >
<Grid.RowDefinitions>
<RowDefinition Height="100" />
<RowDefinition Height="100" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.5*" />
<ColumnDefinition Width="0.5*" />
</Grid.ColumnDefinitions>
<Button Text="Hello, world" Grid.Column="0" Grid.Row="0"></Button>
<Button Text="Hello, world" Grid.Column="1" Grid.Row="0"></Button>
</Grid>
</ScrollView>
</ContentPage>
是否可以自动设置按钮参数Grid.Row和Grid.Column?不是手动的
是否可以自动设置按钮参数Grid.Row和Grid.Column?不是人工的
正如Jason所说,
网格
不会自动排列子视图。默认情况下,Grid.Row
或Grid.Column
的值将为0
对于此功能,请尝试设置为使用。将ItemsLayout设置为GridItemsLayout以垂直网格显示项目
检查代码:
<CollectionView>
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical" Span="2"/>
</CollectionView.ItemsLayout>
<CollectionView.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>Hello, world</x:String>
<x:String>Hello, world</x:String>
<x:String>Hello, world</x:String>
<x:String>Hello, world</x:String>
</x:Array>
</CollectionView.ItemsSource>
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout>
<Button Text="{Binding }"/>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
你好,世界
你好,世界
你好,世界
你好,世界
没有。这怎么行?如果不指定显式值,它将默认为0@Jason,我希望元素本身分布在网格上。这一切都无法以任何方式实现?不。如果您想要一个简单的左-右上-下分布,可以尝试使用CollectionView。如果您想要一个简单的左-右上-下分布,网格
将不会自动排列子视图。对于此功能,请尝试设置为使用。将ItemsLayout设置为GridItemsLayout以在垂直网格中显示项目。