【发布时间】:2019-02-13 08:30:39
【问题描述】:
我正在创建一个存储所有订单的购物车,如何在 ListView 中显示列表?
我试着做这些代码
CustomerOrder.cs
public class CustomerOrder
{
public string menuname { get; set; }
public string price { get; set; }
public string qty { get; set; }
public string mcode { get; set; }
}
public class CustList
{
//i want to display/bind this in Listview
public List<CustomerOrder> CUSTOMER_ORDER { get; set; }
}
OrderCart.xaml
<ListView x:Name="MyCart" ItemSelected="MyCart_ItemSelected" ItemsSource="{Binding CUSTOMER_ORDER}" RowHeight="50">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell >
<Grid>
<StackLayout Orientation="Horizontal">
<Label Text="{Binding menuname}" Font="30" TextColor="Black" FontAttributes="Bold"/>
<Label Text="{Binding qty}" Font="30" TextColor="Black" FontAttributes="Bold"/>
<Label Text="{Binding price}" Font="30" TextColor="Black" FontAttributes="Bold"/>
<Label Text="{Binding mcode}" Font="30" TextColor="Black" FontAttributes="Bold"/>
</StackLayout>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
【问题讨论】:
-
我在您的示例中没有看到二维数组。是否缺少代码?
-
@SwapnilShah 我编辑了它我的意思是列表不是数组谢谢!进行更正。
标签: c# xaml xamarin xamarin.forms