The model is a domain object - in short, what you get from WCF. The model represents the actual data and / or information we are dealing with.
View is a data view. MVVM contains behavior, events, and data bindings, which ultimately require knowledge of the base model and the view model. In short, this is your XAML UserControl.
Viewmodel is the concept of keeping the view nuances separate from the model. On the one hand, it handles all event bindings, and on the other, it knows how to build a model and call a WCF service.
View:
<UserControl x:Class="MVVMExample.DetailView"> <DataGrid ItemsSource="{Binding Path=LineItems}" /> <Button Command="{Binding Path=SubmitCommand}" CommandParameter="SubmitPost"/> </UserControl>
ViewModel:
public class OrderViewModel : BindableBase { public OrderViewModel( IWcfPostService postService ) { this.LineItems = new ObservableCollection<PostItem>( postService.GetPostsList() ); this.SubmitCommand = new DelegateCommand<object>( this.OnSubmit, this.CanSubmit ); } public ObservableCollection<PostItem> LineItems { get; private set; } public ICommand SubmitCommand { get; private set; } private void OnSubmit(object arg) {...} private bool CanSubmit(object arg) { return true; } }
Model:
public class PostModel : INotifyPropertyChanged { private string _author; private string _text; public string Author { get { return _author; } set { _author = value; RaisePropertyChanged("Author"); } } public string Text { get { return _text; } set { _text = value; RaisePropertyChanged("Text"); } } protected void RaisePropertyChanged(string propertyName) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs(propertyName)); } } public event PropertyChangedEventHandler PropertyChanged; }