UWP 静态绑定失败

UWP static binding failed

我有一个 DataGrid,它的 ItemsSource 绑定到 ObservableCollecion<Music> 类型的静态变量 像这样:

        ItemsSource="{Binding AllSongs, Mode=OneWay}"

这个名为 AllSongs 的变量与 DataGrid 在同一页中声明。

但是,DataGrid 没有在 AllSongs 中显示 Data。我已经在构造函数中手动设置了这个 MusicLibraryDataGrid.ItemsSource = AllSongs; 。为什么会这样?

另外一个问题是,我手动设置后,为什么在AllSongs上修改,比如排序,在DataGrid上没有反应?这意味着 DataGrid.ItemsSourceAllSongs 不同步。是否可以使它们同步?

我的第二个问题的可能解决方案是注册 AllSongsCollectionChanged 事件以在其中执行 MusicLibraryDataGrid.ItemsSource = AllSongs;。这种重新绑定会损害性能吗?

据我所知绑定静态 属性 是不允许的。 我要做的是在 class 上创建一个 属性 从静态的读取。

这里讨论过:https://social.msdn.microsoft.com/Forums/windowsapps/en-US/e0e426ba-4feb-4571-b80b-7ba8818079b6/uwpstatic-property-binding?forum=wpdevelop