我正在创建一个购物车,用于存储所有订单,如何在 ListView 中显示列表?
我尝试做这些代码
客户订单.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; }
}
订单购物车.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>
您可能缺少 PropertyChanged 事件。
public class CustList:INotifyPropertyChanged
{
//i want to display/bind this in Listview
private List<CustomerOrder> _CUSTOMER_ORDER
public List<CustomerOrder> CUSTOMER_ORDER
{
get{return _CUSTOMER_ORDER;}
set{
_CUSTOMER_ORDER=value;
OnPropertyChanged("CUSTOMER_ORDER");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this,
new PropertyChangedEventArgs(propertyName));
}
}
另一件事是,如果您缺少的话,您必须为您的 xaml 应用绑定上下文。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)