title: Remove item from ItemsControl
body: <p>I have some <code>UserControls</code> inside of an <code>ItemsControl</code>.</p>
  
  <p>Each <code>UserControl</code> (called <code>JobView</code> in my case) has a <code>ContextMenu</code> with 1 <code>Item</code>('Remove').</p>
  
  <p>Now when the Item on the <code>UserControls ContextMenu</code> is <code>Clicked</code> I want to remove it from the <code>ItemsControlItemCollection</code>.</p>
  
  <p>For that I need to get the <code>Item</code>, the ContextMenu is assigned to.</p>
  
  <p>Currently I am using this:</p>
  
  <pre><code>private void Item_Click(object sender, RoutedEventArgs e)
  {
  
      MenuItem item = (MenuItem)sender;
      JobView view = null;
  
      FrameworkElement currentObject = item;
      while(1 == 1)
      {
          currentObject = currentObject.Parent as FrameworkElement;
          if(currentObject.GetType() == typeof(System.Windows.Controls.Primitives.Popup))
          {
              view = (currentObject as System.Windows.Controls.Primitives.Popup).PlacementTarget as JobView;
              break;
          }
       }
       //Remove from ObservableCollection&lt;JobView&gt;:
       JobViews.Remove(view);
  }
  </code></pre>
  
  <p>It is working fine but I am pretty sure that there must me some better solution.</p>
  
  <p>Took me some time to figure that one out but I can't get to a different solution myself.</p>
  
  <p><strong>How can I get the <code>JobView</code> using the <code>sender</code> object
  or is using <code>sender</code>completely wrong in this case ?</strong></p>