title: TwoWay binding listbox - removing item
body: <p>I have a <code>ListBox</code> (x:Name = <code>notesList</code>) in my WPF application which takes items by <code>ItemsSource</code> from collection. The collection is a <code>Notes</code> property in my class <code>Data</code> and is of type <code>ObservableCollection&lt;Note&gt;</code>. I bind it this way: (<code>data</code> is a <code>Data</code> object that have some items in <code>Notes</code>)</p>
  
  <pre><code>Binding bind = new Binding();
  bind.Mode = BindingMode.TwoWay;
  bind.Source = data;
  bind.Path = new PropertyPath("Notes");
  notesList.SetBinding(ListBox.ItemsSourceProperty, bind);
  </code></pre>
  
  <p>The binding works, items are shown in ListBox. I set TwoWay binding, because I want the <code>notesList</code> and <code>Notes</code> collection to be synchronized. The problem occurs when I try to remove selected item this way:</p>
  
  <pre><code>NotesList.Items.RemoveAt( notesList.SelectedIndex );
  </code></pre>
  
  <p>I get exception: "Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead".</p>
  
  <p>My question: Do I have to use collection function to remove element? <code>data.Notes.RemoveAt(index)</code> ? Is there any way to remove item using <code>ListBox</code> class so it will result removing item in collection? I thought that using TwoWay Binding it will be possible.</p>