I am new to MVVM and am writting a little test-application using it. I've got a Model, which represents the data structure - a ViewModel and a View (parent class is Page), too.
Now i would like to pass some initial data to the Model, so the window could show me these.
In a sample application of David Anderson, he passes the data as method-parameter, which is actually the right way and causes not the trigger of the PropertyChanged-Event, but my Model-class is quite "fat" - it gots a lot of properties (> 30). So, how shall i realize it in this case? I don't think a method with more then 30 parameters is the right way to handle that. Or am i wrong?
Does someone has an idea, how professionals realize this?
Here is my used code:
View (PersonPropertiesView is a subclass of the Page-class)
XAML
<TextBlock Text="{Binding Person.ID, UpdateSourceTrigger=PropertyChanged}" />
Code-Behind
public PersonPropertiesView()
{
InitializeComponent();
this.DataContext = new PersonPropertiesViewModel();
}
ViewModel (PersonPropertiesViewModel)
Code
private Person _Person;
public Person Person
{
get
{
return this._Person;
}
}
public Person()
{
this._Person = new Individual();
this._Person.ID = 12;
}
Model (Person, inherits INotifyPropertyChanged)
private long _ID;
public long ID
{
get
{
return this._ID;
}
set
{
if (this._ID != value)
{
this._ID = value;
OnPropertyChanged("ID");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
if (propertyName != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
If i try to compile this code, i get the System.Reflection.TargetInvocationException exception. Does someone knows why?