title: Databinding a ObservableCollection<T> in MVVM
body: <p>I have a ListView with a Datatemplate that holds a list of Movies. It is databinded to a ObservableColection but whenever I edit the Movie.Name it does not update the ListView even though "Name" is called in my PropertyChangedEventHandler is called with "Name".</p>
  
  <p>I add 2 "Movie"s to my collection in my initializer and these are shown correct (Klovn the Movie, Taken)</p>
  
  <p>So when I click Edit it should change the text of the selected movie and change the Name of it to "Test" and is <em>is</em> changed but the change is not shown in the ListView but if I output Collection with a foreach then Name is Test.</p>
  
  <p>View.xaml</p>
  
  
  
  <pre class="lang-xml prettyprint-override"><code>&lt;Window x:Class="MovieDB3.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="MainWindow" Height="350" Width="525"&gt;
      &lt;DockPanel&gt;
          &lt;Menu DockPanel.Dock="Top"&gt;
              &lt;MenuItem Header="File"&gt;
                  &lt;MenuItem Header="Edit" Click="MenuEditClick"/&gt;
              &lt;/MenuItem&gt;
          &lt;/Menu&gt;
          &lt;Grid DockPanel.Dock="Top"&gt;
              &lt;Grid.ColumnDefinitions&gt;
                  &lt;ColumnDefinition/&gt;
                  &lt;ColumnDefinition/&gt;
              &lt;/Grid.ColumnDefinitions&gt;
              &lt;Grid.RowDefinitions&gt;
                  &lt;RowDefinition/&gt;
              &lt;/Grid.RowDefinitions&gt;
              &lt;ListView VerticalAlignment="Stretch" Name="ListViewMovies" ItemsSource="{Binding Path=Collection}" IsSynchronizedWithCurrentItem="True" &gt;
                  &lt;ListView.ItemTemplate&gt;
                      &lt;DataTemplate&gt;
                          &lt;WrapPanel&gt;
                              &lt;TextBlock Text="{Binding Path=Name}"/&gt;
                          &lt;/WrapPanel&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/ListView.ItemTemplate&gt;
              &lt;/ListView&gt;
          &lt;/Grid&gt;
      &lt;/DockPanel&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>View.cs</p>
  
  <pre><code>using System;
  using System.Windows;
  using MovieDB3.Models;
  using MovieDB3.ViewModels;
  
  namespace MovieDB3
  {
      /// &lt;summary&gt;
      /// Interaction logic for MainWindow.xaml
      /// &lt;/summary&gt;
      public partial class MainWindow : Window
      {
          private MainViewModel MVM;
          public MainWindow()
          {
              InitializeComponent();
              MVM = new MainViewModel();
              DataContext = MVM;
          }
  
          private void MenuEditClick(object sender, RoutedEventArgs e)
          {
              MVM.setMovieName((Movie)ListViewMovies.SelectedItem, "test");
          }
      }
  }
  </code></pre>
  
  <p>The ViewModel</p>
  
  <pre><code>using System;
  using System.ComponentModel;
  using MovieDB3.Models;
  using System.Collections.ObjectModel;
  
  namespace MovieDB3.ViewModels
  {
      class MainViewModel : INotifyPropertyChanged
      {
          public ObservableCollection&lt;Movie&gt; Collection {get; set;}
  
          public MainViewModel()
          {
              Collection = new ObservableCollection&lt;Movie&gt;();
  
              //Test kode
              Movie movie = new Movie();
              movie.Name = "Klovn The Movie";
              Collection.Add(movie);
              movie = new Movie();
              movie.Name = "Taken";
              Collection.Add(movie);
          }
  
          public void setMovieName(Movie movie, string newName)
          {
              //movie.Name = newName;
              Console.WriteLine("CurrentName: " + movie.Name);
              int i = Collection.IndexOf(movie);
              Collection[i].Name = newName;
              Console.WriteLine("NewName: " + movie.Name);
              NotifyPropertyChanged("Name");
          }
  
          public void setMovieName(string currentName, string newName)
          {
              foreach (Movie movie in Collection)
              {
                  if (movie.Name.Equals(currentName))
                  {
                      movie.Name = newName;
                      NotifyPropertyChanged("Name");
                      return;
                  }
              }
          }
  
          //public string MovieName
          //{
          //    set 
          //    {
  
          //        NotifyPropertyChanged("MovieName");
          //    }
          //}
  
          public event PropertyChangedEventHandler PropertyChanged;
  
          private void NotifyPropertyChanged(String info)
          {
              if (PropertyChanged != null)
              {
                  PropertyChanged(this, new PropertyChangedEventArgs(info));
              }
          }
      }
  }
  </code></pre>
  
  <p>Movie.cs</p>
  
  <pre><code>using System;
  
  namespace MovieDB3.Models
  {
      class Movie
      {
          public string Name { get; set; }
          public int Id { get; set; }
          public double Rating { get; set; }
          public DateTime Release { get; set; }
          public TimeSpan Runtime { get; set; }
          public String Trailer { get; set; }
      }
  }
  </code></pre>