WPF中动态加载数据<ItemsControl>

本文深入探讨了在WPF中如何利用ItemsControl动态加载数据,包括数据绑定、ItemTemplate设置以及更新数据的方法,帮助开发者实现更灵活的界面展示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!--动态生成一组按钮-->
 <StackPanel>
    <ItemsControl ItemsSource="{Binding Picture}">
        <ItemsControl.ItemsPanel>
              <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal"/>
              </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        
private ObservableCollection<DetectDetail> detailtable = new ObservableCollection<DetectDetail>(); public ObservableCollection<DetectDetail> DetailTable { get { return detailtable; } set { if (detailtable != value) { detailtable = value; RaisePropertyChanged(() => DetailTable); } } }public class DetectDetail : ViewModelBase { /// <summary> /// 区域 /// </summary> private string _Area = ""; public string Area { get { return _Area; } set { if (_Area != value) { _Area = value; RaisePropertyChanged(() => Area); } } } /// <summary> /// VIN /// </summary> private string _AutoVin = ""; public string AutoVin { get { return _AutoVin; } set { if (_AutoVin != value) { _AutoVin = value; RaisePropertyChanged(() => AutoVin); } } } /// <summary> /// 大数据错误码 /// </summary> private string _ErrCode = ""; public string ErrCode { get { return _ErrCode; } set { if (_ErrCode != value) { _ErrCode = value; RaisePropertyChanged(() => ErrCode); } } } } if (ModelRR.ResultDS.Tables[3].Rows.Count > 0) { var DetectDetailTable = ModelRR.ResultDS.Tables[3]; ObservableCollection<DetectDetail> table = new ObservableCollection<DetectDetail>(); for (int i = 0; i < DetectDetailTable.Rows.Count; i++) { DetectDetail rowData = new DetectDetail(); rowData.Area = DetectDetailTable.Rows[i]["Area"].ToString().Trim(); rowData.AutoVin = DetectDetailTable.Rows[i]["AutoVin"].ToString(); rowData.ErrCode = DetectDetailTable.Rows[i]["ErrCode"].ToString(); table.Add(rowData); } DetectData.DetailTable = table; }这是model和viemodel的相关代码,现在要求实现做一个三行的表格,表格第一行是Area的所有数据,第二行是VIN的所有数据,第三行是detail的所有数据
03-22
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值