I have a generic ViewModel:
ViewModel
public class GenericViewModel<T>
{
public IList<T> SomeList {get; set;}
}
I have to bind the MainWindow's DataContext to this GenericViewModel
. However, I do not know how I should put the thing for <T>
:
MainWindow's Code Behind
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.DataContext = new GenericViewModel<????>(); // What should I put
}
}
The reason I would like to make the ViewModel generic is, I want the List inside it to accept any class's object passed to it, and I have made several dummy class to test it:
DummyModel1
public class DummyModel1
{
public string Name { get; set; }
public string ID { get; set; }
}
DummyModel2
public class DummyModel2
{
public string Name { get; set; }
public string ID { get; set; }
public string Sex { get; set; }
public string Email { get; set; }
}
So, how should I do?
In addition, is there any way to make the application know what the object class passed in before initialize the application?