Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Info

If there is a single model on a view model, the name of the model in the ViewModelToModel can be ommitted as shown in the code below:

 

Code Block
[ViewModelToModel]
public string FirstName
{
    get { return GetValue<string>(FirstNameProperty); }
    set { SetValue(FirstNameProperty, value); }
}

public static readonly PropertyData FirstNameProperty = RegisterProperty("FirstName", typeof(string));

 

The ViewModelToModelAttribute in the code example above automatically maps the view model FirstName and LastName properties to the Person.FirstName and Person.LastName properties. This way, you don’t have to manually map the values from and to the model. Another nice effect is that the view model automatically validates all objects defined using the ModelAttribute, and all field and business errors mapped are automatically mapped to the view model.

...