问题
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