Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个使用带有数据网格的 MVVM 的 wpf 应用程序。我在 viewModel 中设置了 selectedIndex 属性,但 SelectedItems 属性为空。它不应该选择选定的项目吗?
不必要。
一种方法是将数据网格 xaml 中的 SelectedItem 属性设置为视图模型上实现 INotifyPropertyChanged 的属性。然后将xaml绑定模式设置为双向。
然后,如果您单击所选项目,它将触发 xaml 绑定的更改以更新视图模型中的值