问题描述
WPF的新手,请多多包涵...
假设我在SQL中有2个表
事情
其他
两者具有完全相同的字段:
ID(int)
名称(字符串)
说明(字符串)
IsActive(位/布尔)
DateModified(DateTime)
因此,我想创建一个模型(而不是两个)并执行以下操作:
New to WPF, so please bear with me...
Suppose I have 2 tables in SQL
Thing
OtherThing
Both have the exact same fields:
ID (int)
Name (string)
Description (string)
IsActive (bit/bool)
DateModified (DateTime)
So, I want to create one Model (not two) and do something like this:
BaseModel<T>()
{
public int ID {get;set;}
...
}
等等.(当然,使用INotifyPropertyChanged,只是试图保持代码简单).
我希望能够创建可以与任何符合Thing/OtherThing的模型一起使用的BaseView和BaseViewModel.
我真的不知该如何使用此通用名称,因此我不必拥有ThingView/ThingViewModel和OtherThingView/OtherThingViewModel ...
看来这应该很简单,但我似乎无法弄清楚.有没有人有一个代码示例,他们可以使用ONE视图,ONE ViewModel和ONE数据模型互换下拉列表中的各种项目?
etc. (of course, using the INotifyPropertyChanged, just trying to keep the code simple).
I want to be able to create a BaseView and BaseViewModel that would work with whatever model conforms to the Thing/OtherThing.
I am really at a loss as to what to do here to make this generic, so I don''t have to have a ThingView/ThingViewModel and a OtherThingView/OtherThingViewModel...
It seems that this should be simple, but I cannot seem to figure it out. Does anyone have a code example where they could interchange various items from a dropdown list using ONE view, ONE ViewModel, and ONE datamodel?
推荐答案
这篇关于使用泛型的WPF View/ViewModels-怎么做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!