title: how to get the text in a context menu item which is added in the run time?
body: <p>I have created a contextmenu in a wpf form.And menu items are added in the run time.
  following is the XAML code snippet to add the context menu:</p>
  
  <pre><code> &lt;Window.ContextMenu&gt;        
   &lt;ContextMenu AllowDrop="True" VerticalContentAlignment="Top" Opened="note_Opened" &gt;
   &lt;MenuItem Header="View Notes" Click="MenuItemViewNotes_Click"  Name="mainMenu" /&gt;
    ...............................       
  &lt;/ContextMenu&gt;
  &lt;/Window.ContextMenu&gt;
  </code></pre>
  
  <p>menu items are added as following:</p>
  
  <pre><code>private void note_Opened(object sender, RoutedEventArgs e)
      {       
  ......... //some codes goes here   
              while(reader.Read()){ 
  
                  MenuItem newItem = new MenuItem();
                  newItem.Header = textEncrypt.DecryptString(reader[2].ToString());
                 // newItem.Click += new RoutedEventHandler(MenuItemViewNotes_Click);
  
                  mainMenu.Items.Add(newItem);
  
                                  }
          }
  
  
      }
  </code></pre>
  
  <p>following is the "MenuItemViewNotes_Click" methods .I want to get the coresponding index of the clicked menu item.But I was unable to give name or index when I adding the item in the above method.Is there any way to do that?</p>
  
  <pre><code>private void MenuItemViewNotes_Click(object sender, RoutedEventArgs e)
      {        
    mainMenu.Items.Clear();
              MenuItem mi = sender as MenuItem;
  
              if (mi!= null)
              {
                  MessageBox.Show(mi.Header.ToString());
  
              }            
      }
  </code></pre>
  
  <p>here I didn't get any out put.I think it may be some thing wrong in even handling.</p>
  
  <p>again following is the xaml code where call to the   "note_opend " and "MainItemViewNotes_click" functions</p>
  
  <pre><code>&lt;ContextMenu AllowDrop="True" VerticalContentAlignment="Top" Opened="note_Opened" &gt;
          &lt;MenuItem Header="View Notes"   Name="mainMenu"  &gt;
              &lt;MenuItem Header="note1" Click="MenuItemViewNotes_Click"  IsCheckable="True"/&gt;
          &lt;/MenuItem&gt;
  
          &lt;MenuItem Header="Settings" Click="MenuItemSettings_Click"/&gt;
              &lt;MenuItem Header="Close" Click="MenuItemClose_Click"/&gt;
      &lt;/ContextMenu&gt;
  </code></pre>