C# 显示多行绑定对象的StackLayout
我有一个C# 显示多行绑定对象的StackLayout,c#,xaml,xamarin.forms,C#,Xaml,Xamarin.forms,我有一个StackLayout,在网格布局中有绑定元素。 stackLayout显示了一系列对象,我希望当它水平到达屏幕末端时,对象通过包装继续显示它们,因此一个简单的标签。问题是,对象总是只在一行上显示给我,而我无法全部看到它们 这是我的代码: <StackLayout Grid.Row="2" Grid.Column="2" Bind
StackLayout
,在网格
布局中有绑定
元素。
stackLayout
显示了一系列对象,我希望当它水平到达屏幕末端时,对象通过包装继续显示它们,因此一个简单的标签
。问题是,对象总是只在一行上显示给我,而我无法全部看到它们
这是我的代码:
<StackLayout
Grid.Row="2"
Grid.Column="2"
BindableLayout.ItemsSource="{Binding IconDiaries}"
VerticalOptions="FillAndExpand"
Orientation="Horizontal">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Grid RowSpacing="0.5">
<Grid.RowDefinitions>
<RowDefinition Height="17"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="18"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<BoxView BackgroundColor="Gray" Grid.ColumnSpan="2" Grid.Row="0" CornerRadius="5" Opacity="0.6" />
<Image Grid.Row="0" Grid.Column="0" Source="{Binding isSource}" Margin="3"/>
<Label Grid.Row="0" Grid.Column="1" Text="{Binding id}" TextColor="Black" FontSize="12" VerticalTextAlignment="Center" Margin="0,0,3,0"/>
</Grid>
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
stacklayout无法实现此功能,您可以使用collectionview将itemsLayout设置为gridLayout您需要的是包装,它由FlexLayout
根据需要修改这些属性
包裹
对齐项目
方向
调整内容
以获得所需结果
<FlexLayout BindableLayout.ItemsSource="{Binding YourItemSource}"
Wrap="Wrap" JustifyContent="Start" Direction="Row" AlignItems="Start" AlignContent="Start">
<BindableLayout.ItemTemplate>
<DataTemplate>
<!-- Your Template -->
</DataTemplate>
</BindableLayout.ItemTemplate>
</FlexLayout>
另一个帮助你的人我解决了我的问题