如何解决Xamarin List <List>的列表视图 在Xaml中
我正在制作一个移动应用程序,并且试图在列表视图中加载列表。该列表包含多个元素和一个列表:
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
}
}
}
}
如何使用x:Name =“ StacklayoutMap”在堆栈布局中从Users.Name列出列表
<ListView x:Name="lvPropositions" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Frame BorderColor="Black" Margin="10,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>
解决方法
您可以使用可绑定版式
在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>
有关可绑定布局的更多详细信息,您可以参考此 doc 。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。