title: Save Changes of View in Viewmodel?
body: <p>I'm trying to display a model and I want to save it when the user clicks a button.
  (Bind ModelView OneWay to Model and if the save button was pressed I update the source manually.)
   Is that possible?</p>
  
  <p>Here I created a small example with my problem. (not MVVM!)</p>
  
  <p><strong>MainWindow.xaml</strong></p>
  
  <pre><code>&lt;Grid&gt;
          &lt;Grid.DataContext&gt;
              &lt;ViewModel:MainViewModel/&gt;
          &lt;/Grid.DataContext&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition/&gt;
              &lt;ColumnDefinition/&gt;
          &lt;/Grid.ColumnDefinitions&gt;
          &lt;local:PersonListView Grid.Column="0" DataContext="{Binding ViewModel_PersonList}"/&gt;
          &lt;local:PersonView Grid.Column="1" DataContext="{Binding ViewModel_Person}"/&gt;
      &lt;/Grid&gt;
  </code></pre>
  
  <p><strong>PersonListView.xaml</strong></p>
  
  <pre><code>&lt;ListView ItemsSource="{Binding PersonList}" SelectedItem="{Binding SelectedPerson}"&gt;
          &lt;ListView.ItemTemplate&gt;
              &lt;DataTemplate&gt;
                  &lt;TextBlock Text="{Binding LastName}"/&gt;
              &lt;/DataTemplate&gt;
          &lt;/ListView.ItemTemplate&gt;
      &lt;/ListView&gt;
  </code></pre>
  
  <p><strong>PersonView.xaml</strong></p>
  
  <pre><code>&lt;Grid DataContext="{Binding}"&gt;
      &lt;Grid.ColumnDefinitions&gt;
          &lt;ColumnDefinition/&gt;
          &lt;ColumnDefinition/&gt;
      &lt;/Grid.ColumnDefinitions&gt;
      &lt;Grid.RowDefinitions&gt;
          &lt;RowDefinition Height="auto"/&gt;
          &lt;RowDefinition Height="auto"/&gt;
          &lt;RowDefinition Height="auto"/&gt;
          &lt;RowDefinition/&gt;
          &lt;RowDefinition Height="auto"/&gt;
      &lt;/Grid.RowDefinitions&gt;
      &lt;TextBlock Text="First Name:" Grid.Column="0" Grid.Row="0" Margin="5"/&gt;
      &lt;TextBlock Text="Last Name:" Grid.Column="0" Grid.Row="1" Margin="5"/&gt;
      &lt;TextBlock Text="Age:" Grid.Column="0" Grid.Row="2" Margin="5"/&gt;
      &lt;TextBox Text="{Binding Path=Person.FirstName, UpdateSourceTrigger=Explicit}" Grid.Column="1" Grid.Row="0" Margin="5"/&gt;
      &lt;TextBox Text="{Binding Path=Person.LastName, UpdateSourceTrigger=Explicit}" Grid.Column="1" Grid.Row="1" Margin="5"/&gt;
      &lt;TextBox Text="{Binding Path=Person.Age, UpdateSourceTrigger=Explicit}" Grid.Column="1" Grid.Row="2" Margin="5"/&gt;
      &lt;Button Content="Save" Command="{Binding SaveCommand}" Grid.Column="1" Grid.Row="4"/&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p><strong>Person.cs</strong></p>
  
  <pre><code>public class Person : INotifyPropertyChanged
      {
          private string firstName;
          public string FirstName
          {
              get { return firstName; }
              set
              {
                  firstName = value;
                  OnPropertyChanged("FirstName");
              }
          }
  
          private string lastName;
          public string LastName
          {
              get { return lastName; }
              set
              {
                  lastName = value;
                  OnPropertyChanged("LastName");
              }
          }
  
          private int age;
          public int Age
          {
              get { return age; }
              set
              {
                  age = value;
                  OnPropertyChanged("Age");
              }
          }
  
          public event PropertyChangedEventHandler PropertyChanged;
  
          private void OnPropertyChanged(string propertyName)
          {
              if (PropertyChanged != null)
                  PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
          }
      }
  </code></pre>
  
  <p><strong>MainViewModel.cs</strong></p>
  
  <pre><code>public class MainViewModel : ViewModelBase
      {
          /// &lt;summary&gt;
          /// Initializes a new instance of the MainViewModel class.
          /// &lt;/summary&gt;
          public MainViewModel()
          {
              ViewModel_PersonList.PersonList.Add(new Model.Person()
              {
                  LastName = "Test",
                  FirstName = "John",
                  Age = 20
              });
              ViewModel_PersonList.PersonList.Add(new Model.Person()
              {
                  LastName = "Example",
                  FirstName = "Luke",
                  Age = 25
              });
              ViewModel_PersonList.SelectedPerson = ViewModel_PersonList.PersonList[1];
  
              ViewModel_Person.Person = ViewModel_PersonList.SelectedPerson;
          }
  
          ViewModel.PersonViewModel _ViewModel_Person = new ViewModel.PersonViewModel();
          public ViewModel.PersonViewModel ViewModel_Person
          {
              get
              {
                  return _ViewModel_Person;
              }
              set
              {
                  _ViewModel_Person = value;
                  RaisePropertyChanged("ViewModel_Person");
              }
          }
  
          ViewModel.PersonListViewModel _ViewModel_PersonList = new ViewModel.PersonListViewModel();
          public ViewModel.PersonListViewModel ViewModel_PersonList
          {
              get
              {
                  return _ViewModel_PersonList;
              }
              set
              {
                  _ViewModel_PersonList = value;
                  RaisePropertyChanged("ViewModel_PersonList");
              }
          }
      }
  </code></pre>
  
  <p><strong>PersonListViewModel.css</strong></p>
  
  <pre><code> public class PersonListViewModel : ViewModelBase
      {
          ObservableCollection&lt;Model.Person&gt; _PersonList = new ObservableCollection&lt;Model.Person&gt;();
          public ObservableCollection&lt;Model.Person&gt; PersonList
          {
              get
              {
                  return _PersonList;
              }
              set
              {
                  _PersonList = value;
                  RaisePropertyChanged("PersonList");
              }
          }
  
          Model.Person _SelectedPerson = new Model.Person();
          public Model.Person SelectedPerson
          {
              get
              {
                  return _SelectedPerson;
              }
              set
              {
                  MessengerInstance.Send&lt;Model.Person&gt;(value);
                  _SelectedPerson = value;
                  RaisePropertyChanged("SelectedPerson");
              }
          }
      }
  </code></pre>
  
  <p><strong>PersonViewModel.cs</strong></p>
  
  <pre><code>public class PersonViewModel : ViewModelBase
      {
          public PersonViewModel()
          {
              MessengerInstance.Register&lt;Model.Person&gt;(this, per =&gt; Person = per);
          }
  
          Model.Person _Person = new Model.Person();
          public Model.Person Person
          {
              get
              {
                  return _Person;
              }
              set
              {
                  _Person = value;
                  RaisePropertyChanged("Person");
              }
          }
  
          private RelayCommand&lt;Model.Person&gt; _SaveCommand;
          public ICommand SaveCommand
          {
              get
              {
                  if (_SaveCommand == null)
                      _SaveCommand = new RelayCommand&lt;Model.Person&gt;(SaveCommand_Execute, SaveCommand_CanExecute);
                  return _SaveCommand;
              }
          }
  
          private bool SaveCommand_CanExecute(Model.Person newPerson)
          {
              return true;
          }
  
          private void SaveCommand_Execute(Model.Person newPerson)
          {
  // Do my saving!
          }
      }
  </code></pre>
  
  <p>Thank you!</p>