【发布时间】:2019-09-06 03:30:21
【问题描述】:
我有一个DataGrid,其ItemsSource 绑定到ObservableCollecion<Music> 类型的静态变量
像这样:
ItemsSource="{Binding AllSongs, Mode=OneWay}"
此变量名为AllSongs,与DataGrid 在同一页面中声明。
但是,DataGrid 没有在AllSongs 中显示Data。我在构造函数中手动设置了这个MusicLibraryDataGrid.ItemsSource = AllSongs;。为什么会这样?
另一个问题是,我手动设置后,为什么对AllSongs的修改像排序一样不会反映在DataGrid上?这意味着DataGrid.ItemsSource 与AllSongs 不同步。是否可以使它们同步?
我的第二个问题的可能解决方案可能是注册AllSongs 的CollectionChanged 事件以在其中执行MusicLibraryDataGrid.ItemsSource = AllSongs;。这种重新绑定会损害性能吗?
【问题讨论】:
标签: c# xaml uwp win-universal-app