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.
我对 WPF/MVVM 还很陌生,但是我已经阅读了很多教程并完成了一些小项目,因此有了初步的了解。
我的问题:
我有一个模型类,其中包含一组数据。我的主视图必须在 DataGrid 上显示几个模型的数据。我目前的方法是在模型视图中创建一个 DataGrid,方法是使用一个 DataGrid 定义一个 Datatemplate,该 DataGrid 的 ItemsSource 是模型的集合。
这种方法有点工作,但它为每个模型创建了一个数据网格。有谁知道只有一个 DataGrid 的好方法?
如果视图应该显示单个网格,您可能希望使用单个集合创建 ViewModel,并从多个模型集合中填充集合。
这就是 ViewModel 的用途。