【问题标题】:Bound observable collection not showing in list view绑定的可观察集合未显示在列表视图中
【发布时间】:2018-02-06 03:27:30
【问题描述】:

如果我将items 用作ItemsSource,它可以工作,但如果我使用sorted_items,它不会显示在列表视图中。

ObservableCollection<myModel> items = new  ObservableCollection<myModel>();
ObservableCollection<myModel> sorted_items = new  ObservableCollection<myModel>();

lv_items.ItemsSource = sorted_items;

items.Add(new myModel
{
    ImageSource = myImage,
    Name = item_name;
});

sorted_items = items;

for (int j = 0; j < sorted_items.Count; j++)     
{                                                   
    sorted_items.Move(sorted_items.Count - 1, j)
}

【问题讨论】:

  • 这段代码甚至不会编译,因为你在声明它之前使用了sorted_items
  • 我的错,我从头开始写的。无论如何,谢谢

标签: c# wpf binding


【解决方案1】:

我的Spidey 感觉告诉我,你应该在完成任务后尝试移动lv_items.ItemsSource = sorted_items,或者在你完成for 之后更好

for (int j = 0; j < sorted_items.Count; j++)     
{                                                   
   sorted_items.Move(sorted_items.Count - 1, j)
}

lv_items.ItemsSource = sorted_items;

【讨论】:

  • @BrianSanchez 确保将其标记为已回答,如果它适合您的目的 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-16
  • 2015-10-21
  • 1970-01-01
  • 1970-01-01
  • 2016-11-08
  • 1970-01-01
相关资源
最近更新 更多