title: WPF & MVVM : Update an image field without breaking the pattern
body: <p>I'm currently learning how to write a WPF application using the MVVM pattern. I'm writing a little contact manager application, so my app displays a Listbox bound to my View Model, and a set of fields bound to ListBox.SelectedItem. One of these fields is the contact's photo.</p>
  
  <p>I'd like to change the photo in the edit part using OpenFileDialog, so the Listbox item would be updated, as it is for all of the other fields.</p>
  
  <p>I first tried to update the source property of the Image control, but doing this, I lose the Binding... 
  Then I wrote an handler on Button_Click to update the Contact.Photo property (its type is byte[]), and it works. But instead of binding from the "update control" to the view model, binding is from the VM to the control, as if the data came from the DB. </p>
  
  <p>(In the code, LoadPhoto returns a byte[])</p>
  
  <pre><code>private void Button_Click(object sender, RoutedEventArgs e)
  {
      OpenFileDialog OpenFileDialog = new OpenFileDialog();
      if (OpenFileDialog.ShowDialog() == true)
      {
          (listbox.SelectedItem as ContactManager.ViewModel.Contact).Photo = 
                  LoadPhoto(OpenFileDialog.FileName);
      }
  }
  </code></pre>
  
  <p>I wonder if it doesn't break the MVVM pattern... I'm not sure of what could be made in the View... Is it the right way to update the Contact object ? Does anyone have a better solution to this problem ? </p>