你绑定
ItemsSource在一个属性
DataContext叫
Items,所以要更新集合,你需要去
Items的财产
DataContext和清除。
另外,该
Items属性的类型必须为
ObservableCollection,
List如果您希望在基础集合发生更改时更新UI ,则不需要。
您
ItemsSource不需要在后面的代码中设置代码的位,因此应将其删除。您只需要将其设置
ItemsSource在一个位置,而不是两个都设置。
这是一个如何工作的简单示例:
// Using Students instead of Items for the PropertyName to clarifypublic ObservableCollection<Student> Students { get; set; }public MyConstructor(){ ... Students = search.students(); listBoxSS.DataContext = this;}现在,当您拥有:
<ListView ItemsSource="{Binding Students}" ... />您将绑定
ItemsSource到
ObservableCollection<Student>,并且要清除列表时可以调用:
Students.Clear()



