Mapping properties from view to view model
Sometimes a view (for example, a user control) contains additional properties besides the DataContext to interact with the view model. By default, it is hard to implement this in an MVVM sccenario, but Catel solves this issue using the ViewToViewModel attribute.
This attribute automatically keeps track of changes in both the view and the view model and this way, a control can have several properties and still implement MVVM.
Example implementation
Need to write an example
Mapping types
Catel supports the following mapping types using the ViewToViewModelMappingType enum.
Type | Description |
---|---|
TwoWayDoNothing | Two way, which means that either the view or the view model will update the values of the other party as soon as they are updated. When this value is used, nothing happens when the view model of the view changes. This way, it might be possible that the values of the view and the view model are different. The first one to update next will update the other. |
TwoWayViewWins | Two way, which means that either the view or the view model will update the values of the other party as soon as they are updated. When this value is used, the value of the view is used when the view model of the view is changed, and is directly transferred to the view model value |
TwoWayViewModelWins | Two way, which means that either the view or the view model will update the values of the other party as soon as they are updated. When this value is used, the value of the view model is used when the view model of the view is changed, and is directly transferred to the view value. |
ViewToViewModel | The mapping is from the view to the view model only. |
ViewModelToView | The mapping is from the view model to the view only. |