WPF View/ViewModels using Generics- how?

Posted by Investor5555 on Stack Overflow See other posts from Stack Overflow or by Investor5555
Published on 2010-04-21T02:16:09Z Indexed on 2010/04/21 2:23 UTC
Read the original article Hit count: 287

Filed under:
|
|

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;}
   ...
}

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 base datamodel (and switching out the type from a dropdown)?

For example, a combobox has 3 identical table structures for Thing OtherThing SomeThing

and on selection changed, I want to pull the data from whatever table was selected, to be able to do standard CRUD operations on any of these 3 tables, without having to create concrete classes for each view/viewmodel.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about generics