我正在使用带有自定义ItemsSource的ListBox:
this.ListOfPersonsListBox.ItemsSource = (List<Person>)ListOfPersons.AllPersons;
Run Code Online (Sandbox Code Playgroud)
ListOfPersons是一个静态类,因此它无法实现INotifyPropertyChanged和IObservableCollection.
更新列表后重绘ListBox的最简单方法是什么?我目前的代码有效,但我想找到一个更清洁的解决方案:
private void SyncButton_Click(object sender, EventArgs e)
{
ListOfPersons.Sync();
this.ListOfPersonsListBox.ItemsSource = null;
this.ListOfPersonsListBox.ItemsSource = ListOfPersons.AllPersons;
}
Run Code Online (Sandbox Code Playgroud)