title: Get Selected Item from Context Menu
body: <p>I am creating a set of images dynamically and putting them into a Stack Panel like this :-</p>
  <pre><code>            Image image = new Image();
              image.Name = &quot;image_&quot; + iCounter;
              image.Height = 100;
              image.Width = 100;
              image.Source = bitmap;
              image.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
              image.Stretch = Stretch.Fill;
              image.VerticalAlignment = VerticalAlignment.Top;
              //image.MouseDown += new MouseButtonEventHandler(image_MouseDown);
              image.ToolTip = &quot;Right-Click for Options&quot;;
              image.ContextMenu = GetContextMenu();
  
              Separator separator = new Separator();
              separator.Name = &quot;separator_&quot; + iCounter;
  
              AddImagesStackPanel.Children.Add(image);
              AddImagesStackPanel.Children.Add(separator);
  
              iCounter++;
  </code></pre>
  <p>Then in the Context Menu I have this code :-</p>
  <pre><code>    private System.Windows.Controls.ContextMenu GetContextMenu()
      {
          System.Windows.Controls.MenuItem mi1;
          System.Windows.Controls.MenuItem mi2;
      
          System.Windows.Controls.ContextMenu _contextMenu = new System.Windows.Controls.ContextMenu();
      
          mi1 = new System.Windows.Controls.MenuItem();
          mi1.Header = &quot;Show Normal Size&quot;;
          mi1.Click += new RoutedEventHandler(ContextMenuItem1_Click);
  
          mi2 = new System.Windows.Controls.MenuItem();
          mi2.Header = &quot;Remove image&quot;;
          mi2.Click += new RoutedEventHandler(ContextMenuItem2_Click);
  
          _contextMenu.Items.Add(mi1);
          _contextMenu.Items.Add(mi2);
          return _contextMenu;
      }
  </code></pre>
  <p>Now I wish to get the selected item when the user right clicks on an image and I have this code :-</p>
  <pre><code>    private void ContextMenuItem2_Click(object sender, RoutedEventArgs e)
      {
          object obj = e.OriginalSource;
  
          string imageName = ((System.Windows.Controls.Image)obj).Name;
          string[] split = imageName.Split('_');
          imageUploads.RemoveAt(Convert.ToInt32(split[1]));
          DisplayImagesInStackPanel(imageUploads);
      }
  </code></pre>
  <p>But obj does not contain the name of the image since its a RoutedEventArgs.  Is there any way I can get the selected item in the context menu?</p>