具有动态集合属性的 ViewModel
我正在使用 WPF 和 MVVM 模式。所以我的问题是,辅助窗口/视图的 ViewModel 中是否可能有一个动态属性,该属性将有一些集合。
我的应用程序有不同的自定义类,它们是类别、供应商等集合,我正在尝试创建一个 ViewModel,该 ViewModel 将具有一个属性,以便每次用户想要编辑集合中的项目时拥有这些集合之一。我怀疑这是否可以通过 ViewModel 来实现。
在 ViewModel 中,我有布尔属性来显示或不显示 ListView 中的标签、文本框和一些列。并且将成为 ViewModel 中属性的 Collection 由 ListView 绑定。
我正在尝试通过这种方式,这样我就可以防止为每个要编辑的集合创建窗口/视图。
我的课程:
public class SupplierCollection : CollectionBase, INotifyCollectionChanged, INotifyPropertyChanged
{
(...)
}
public class StateCollection : CollectionBase, INotifyCollectionChanged, INotifyPropertyChanged
{
(...)
}
public class PlaceCollection : CollectionBase, INotifyCollectionChanged, INotifyPropertyChanged
{
(...)
}
提前致谢!
I am working with WPF and the MVVM pattern. So my problem is if it's possible in ViewModel of a secondary window/view have a dynamic property who will have some collection.
My App have different custom classes who are collections like Categories, Suppliers and etc, and i am trying to create a ViewModel who will have a Property to have one of those collections each time the user wants to edit the items of a collection. My doubt is if this is possible to achieve with a ViewModel.
In the ViewModel i have boolean properties to show or not Labels, TextBoxes, and some Columns in a ListView. And the Collection who will be the property in the ViewModel is binded by a ListView.
I am trying to this by this way, so i can prevent from creating a window/view for each collection to be edited.
My Classes:
public class SupplierCollection : CollectionBase, INotifyCollectionChanged, INotifyPropertyChanged
{
(...)
}
public class StateCollection : CollectionBase, INotifyCollectionChanged, INotifyPropertyChanged
{
(...)
}
public class PlaceCollection : CollectionBase, INotifyCollectionChanged, INotifyPropertyChanged
{
(...)
}
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我的注释正确,您可以通过引入以下
enum
来实现您想要的:然后添加到视图模型以下属性:
然后使用
switch
或更解耦的东西,例如If I got your notes right you can achieve what you want by introducing following
enum
:and then add into the View Model following property:
then use
switch
or something more decoupled like