Silverlight MVVM Clutch Model and View Model

There are many great examples in MVVM, but I'm still confused.

Let's say you have a CustomerModel and a CustomerViewModel. It seems that there would be a Name property in the CustomerModel and one in the CustomerViewModel. The installer in the CustomerViewModel will set the CustomerModel Name property, and then call OnPropertyChanged (PropName) to update the user interface. Is this really so? It seems that getters / setters will be defined twice. If you have a model with 50 properties, it will become really tedious.

Also, let's say I set the Qty property. ViewModel updates the model. The model updates the Value property based on the new Qty. How is the notification ViewModel notified that the Model property has changed?

+5
source share
3 answers

ViewModel . CustomerViewModel Customer, , View Model... ViewModel. . , . - . , , -, "". - , . , . , , , "" .

+5

, , CustomerModel , ( ). CustomerViewModel , ( .., , 50 , ), INotifyPropertyChanged, , (, XAML) .

.

public int Name
{
    get
    {
        return this.name;
    }

    set
    {
        if (this.name!= value)
        {
            this.name= value;
            this.OnPropertyChanged("Name");
        }
    }
}

ViewModel - , , , , ObservableCollection < gt; .. XAML.

ViewModel, , , . :

  CustomerViewModel viewModel = new CustomerViewModel(customer);

  CustomerViewModel viewModel = customer.ToViewModel();

ViewModel - ViewModel , . . , "". , , , .

, , ViewModel - , , ViewModel . ViewModel ? , , .

, , -. , , , (, , ) .

+2

, -, wekempf .

Depending on how you display customer information in the user interface, your ViewModel may have ObservableCollection of Customer types (your model). If, for example, you show a master / detail script where you can have a list of clients and show details below when a particular client is selected.

0
source

All Articles