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.ItemsSource
与 AllSongs
不同步。是否可以使它们同步?
我的第二个问题的可能解决方案是注册 AllSongs
的 CollectionChanged
事件以在其中执行 MusicLibraryDataGrid.ItemsSource = AllSongs;
。这种重新绑定会损害性能吗?
据我所知绑定静态 属性 是不允许的。
我要做的是在 class 上创建一个 属性 从静态的读取。
我有一个 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;
。这种重新绑定会损害性能吗?
据我所知绑定静态 属性 是不允许的。 我要做的是在 class 上创建一个 属性 从静态的读取。