title: Bind ObservableCollection to ListView
body: <p>I am having some trouble to bind my collection to my listview. I have tried a lot of different approaches from others on here for binding, and also followed <a href="http://msdn.microsoft.com/en-us/library/ms748365.aspx" rel="nofollow">this tutorial</a> at first. I made it to work but it was not the way I wanted.</p>
  
  <p>Anymway, here is the XML:</p>
  
  <pre><code>    &lt;ListView Grid.Row="0" ItemsSource="{Binding SongList}"  SelectionMode="Extended" x:Name="ListViewMain" VerticalAlignment="Top"  ScrollViewer.VerticalScrollBarVisibility="Visible" Margin="0,1,0,0" Height="264" &gt;
          &lt;ListView.View&gt;
              &lt;GridView&gt;
                  &lt;GridViewColumn Header="Title" DisplayMemberBinding="{Binding Title}" Width="500"/&gt;
                  &lt;GridViewColumn Header="Artist" DisplayMemberBinding="{Binding Artist}" Width="100"/&gt;
                  &lt;GridViewColumn Header="Album" DisplayMemberBinding="{Binding Album}" Width="100"/&gt;
                  &lt;GridViewColumn Header="Length" DisplayMemberBinding="{Binding Length}" Width="100"/&gt;
                  &lt;GridViewColumn Header="Location" DisplayMemberBinding="{Binding Songfile}" Width="100"/&gt;
              &lt;/GridView&gt;
          &lt;/ListView.View&gt;
      &lt;/ListView&gt;
  </code></pre>
  
  <p>In my code, to add items to my collection, I do :</p>
  
  <pre><code>public MainWindow()
  {
       InitializeComponent();
           ...
       PlayListItem addsong = new PlayListItem(title, artist, album, length, filename);
  }
  </code></pre>
  
  <p>The PlayListItem class with the ObservableCollection :</p>
  
  <pre><code>public class PlayListItem
  {
   public ObservableCollection&lt;Song&gt; _SongList = new ObservableCollection&lt;Song&gt;();
   public ObservableCollection&lt;Song&gt; SongList { get { return _SongList; } }       
  
   public PlayListItem(string _Title, string _Artist, string _Album, string _Length, string _Filename)
  {
       _SongList.Add(new Song
      {
       Title = _Title,
       Artist = _Artist,
       Album = _Album,
       Length = _Length,
       SongFile = _Filename,
      });
  }
  
   public class Song
    {
      public string Artist { get; set; }
      public string Album { get; set; }
          public String Title { get; set; }
          public string Length { get; set; }
          public String SongFile { get; set; }
    }
  }
  </code></pre>
  
  <p>I think my items are added correctly each time I call the constructor, but it does not get updated on the ListView. I do not have some errors about the binding in the Output window either.</p>
  
  <p>Any ideas and help would be appreciated.</p>
  
  <p>EDIT :</p>
  
  <p>By adding :</p>
  
  <pre><code>ListViewMain.ItemsSource = addsong.SongList;
  </code></pre>
  
  <p>Right after creating a new PlayListItem seems to solve the problem, as the ListView is now printing the item.</p>