title: C# wpf observablecollection binding to xaml
body: <p>I am trying to use ObservableCollection to bind data from object to xaml view:
  I have a class which has property :</p>
  
  <pre><code>public ObservableCollection&lt;Roll&gt; RollList = new ObservableCollection&lt;Roll&gt;();
  </code></pre>
  
  <p>And some methods that modify that collection (basically method that adds new entries), like this:</p>
  
  <pre><code>RollList.Add(roll); //roll is and Roll class object bellow
  </code></pre>
  
  <p>Here's a roll class that I use in collection:</p>
  
  <pre><code>class Roll : INotifyPropertyChanged
  {
      private List&lt;int&gt; _hitList;
  
      public List&lt;int&gt; HitList
      {
          get { return _hitList; }
          set { _hitList = value; OnPropertyChanged("HitList"); }
      }
  
      public event PropertyChangedEventHandler PropertyChanged;
  
      public void OnPropertyChanged(string name)
      {
          if (PropertyChanged != null)
          {
              PropertyChanged(this, new PropertyChangedEventArgs(name));
          }
      }
  }
  
  public class ListToStringConverter : IValueConverter
  {
      public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
      {
          List&lt;int&gt; list = value as List&lt;int&gt;;
          return String.Join("", list.ToArray());
      }
  
      public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
      {
          string list = value as string;
          return list.Split(' ').Select(n =&gt; int.Parse(n)).ToList();
      }
  }
  </code></pre>
  
  <p>Now in my main window class I instantiate my class which constructs ObservableCollection object above and fills it with data;</p>
  
  <p>I bind my collection to DataContex like so;</p>
  
  <pre><code>DataContext = MyCoolClass; //MyCoolClass has ObservableCollection&lt;Roll&gt; RollList inside of it
  </code></pre>
  
  <p>And last thing I what I do:</p>
  
  <pre><code>&lt;Window.Resources&gt;
      &lt;local:ListToStringConverter x:Key="ListToStringConverter" /&gt;
  &lt;/Window.Resources&gt;
  
  &lt;ListBox 
      Height="Auto" 
      Width="Auto" 
      Name="RollList" 
      ItemsSource="{Binding RollList, Converter={StaticResource ListToStringConverter}}"
  /&gt;
  </code></pre>
  
  <p>In the the listbox doesn't get populated with data. I know that RollList object is filled with data, because I can is it in watch window, and if I assign listbox item source manualy:  </p>
  
  <pre><code>RollList.ItemsSource = ConvertedCollection;
  </code></pre>
  
  <p>It works and listbox is populated with data I wan't, but I want to bind it inside xaml;</p>
  
  <p>PS. I am new to C# and WPF.</p>