绑定的可观察集合未在列表视图中显示

时间:2018-02-06 03:27:30

标签: c# wpf binding

如果我使用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)
}

1 个答案:

答案 0 :(得分:4)

我的 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;
相关问题