Xamarin listview of List<List>

浪子不回头ぞ 提交于 2021-02-16 21:11:21

问题


I'm making a mobile app and I'm trying to load a list in a listview. The list has multiple elements and a list:

public static List<Proposition> PropositionList = new List<Proposition>
{
    new Proposition{
        PropositionId = Guid.Parse("00000000-0000-0000-0000-000000000001"),
        Place= "Barge",
        Date= new DateTime(2020, 7, 11),
        Users= new List<User>(){
            new User
            {
                UserId = Guid.Parse("00000000-0000-0000-0000-000000000001"),
                Name= "Jan Aerts",
                Sterren = 3
            },
            new User
            {
                UserId = Guid.Parse("00000000-0000-0000-0000-000000000002"),
                Naam = "Bart Denys",
                Sterren = 5
            }
        }
    }
}

How do I make a list from Users.Name in my stacklayout with x:Name="StacklayoutMap"

<ListView x:Name="lvPropositions" HasUnevenRows="True">
    <ListView.ItemTemplate>
        <DataTemplate>
             <ViewCell>
                 <Frame BorderColor="Black" Margin="10, 0, 10, 0" CornerRadius="45">
                     <StackLayout StyleClass="listitem" Padding="5">
                         <StackLayout Orientation="Horizontal">
                              <Label Style="{DynamicResource DivesLabelStyle}" Text="{Binding Datum}" VerticalOptions="Center" HorizontalOptions="StartAndExpand" />
                              <Label Style="{DynamicResource DivesLabelStyle}" Text="{Binding Plaats}" VerticalOptions="Center" HorizontalOptions="EndAndExpand" />
                         </StackLayout>
                         <StackLayout Orientation="Horizontal">
                             <StackLayout x:Name="StackLayoutMap">
                                
                              </StackLayout>
                              <ImageButton Source="addBlack.png" BackgroundColor="Transparent" HorizontalOptions="EndAndExpand" VerticalOptions="Center" Clicked="BtnRegister_Clicked"/>
                          </StackLayout>
                     </StackLayout>
                </Frame>
         </ViewCell>
     </DataTemplate>
</ListView.ItemTemplate>

回答1:


You could use Bindable Layout

in Xaml

 <StackLayout Orientation="Horizontal">
     <StackLayout x:Name="StackLayoutMap" BindableLayout.ItemsSource="{Binding Users}">
            <BindableLayout.ItemTemplate>
                <DataTemplate>

                    <Label Text="{Binding Naam}" TextColor="Red" ... />

                </DataTemplate>
            </BindableLayout.ItemTemplate>                     
     </StackLayout>
//...
</StackLayout>

For more details about Bindable Layout you could refer this doc .



来源:https://stackoverflow.com/questions/64569433/xamarin-listview-of-listlist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!