title: ObservableCollection ListBox Item Remove Not Working
body: <p>I have a ListBox with binding, when i add Items it works perfect but if i try to remove the items with contextMenu it doesnt work. </p>
  
  <p>Here is what i try so far <strong>ListBox Xaml Code</strong> </p>
  
  <pre><code>   &lt;ListBox Name="lstPersons"
                       VerticalAlignment="Stretch"
                       HorizontalAlignment="Stretch" Margin="126,-228,2,-242"&gt;
                  &lt;toolkit:ContextMenuService.ContextMenu&gt;
                      &lt;toolkit:ContextMenu Name="PersonContext"&gt;
                          &lt;toolkit:MenuItem Name="PersonDelete" Header="Delete" Click="DeletePerson_Click"/&gt;
                      &lt;/toolkit:ContextMenu&gt;
                  &lt;/toolkit:ContextMenuService.ContextMenu&gt;
                  &lt;ListBox.ItemTemplate&gt;
                      &lt;DataTemplate&gt;
                          &lt;StackPanel&gt;    
                              &lt;TextBlock Name="btnKellnerName"                                      
                                               Text="{Binding _PersonName}" 
                                               FontSize="35" 
                                               FontFamily="Portable User Interface"/&gt;
                              &lt;TextBlock Name="btnPosition"
                                               Text="{Binding _PersonPosition}"
                                               FontSize="22"/&gt;
                              &lt;TextBlock Name="lblUhrzeit" 
                                               Text="{Binding _CreationDate}"
                                               FontSize="18"/&gt;
                              &lt;TextBlock Name="Space" Text="                "/&gt;
                          &lt;/StackPanel&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/ListBox.ItemTemplate&gt;
              &lt;/ListBox&gt;
  </code></pre>
  
  <p>And the <strong>Binding Class Code</strong> </p>
  
  <pre><code>public class Person 
  {    
      public string _PersonName { get; set; }      
      public string _PersonPosition { get; set; }    
      public string _CreationDate { get; set; }   
  }
  </code></pre>
  
  <p>When i add items like this </p>
  
  <pre><code>ObservableCollection&lt;Person&gt; personList = new ObservableCollection&lt;Person&gt;();
  
  personList.Add(new Person { 
  _PersonName = "Tom",
  _PersonPosition = "Bla", 
  _CreationDate = "33"
  });
  
  this.lstPerson.ItemSource = personList;
  </code></pre>
  
  <p>it works pefect! Now i Want to remove a selected Item with the ContextMenu like this </p>
  
  <pre><code>private void DeletePerson_Click(object sender, RoutedEventArgs e)
  {   
     int indexPerson = lstPerson.SelectedIndex;
  
     personList.RemoveAt(indexPerson);
  }    
  </code></pre>
  
  <p>but it doesnt work. Does Anybody have an Idea what im making wrong? <strong>Thanks</strong> </p>
  
  <p>Ok Guys i have now <strong>the Solution</strong> the Problem was the value of SelectedIndex now ive got the right Value. First ive put the ContextMenu inside ListBoxItemTemplate/StackPanel</p>
  
  <p>Code Behind: </p>
  
  <pre><code>private void DeletePerson_Click(object sender, RoutedEventArgs e)
    {
        try {
  
                  var selectedListBoxItem = listBox.ItemContainerGenerator.ContainerFromItem(((MenuItem) sender).DataContext) as ListBoxItem;
                  var selectedIndex = listBox.ItemContainerGenerator.IndexFromContainer(selectedListBoxItem);
  
                  _personList.RemoveAt(selectedIndex);
           }
           catch( Exception ex ) { MessageBox.Show(ex.Message); };
    }    
  </code></pre>