Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 显示多行绑定对象的StackLayout_C#_Xaml_Xamarin.forms - Fatal编程技术网

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>


另一个帮助你的人

我解决了我的问题