title: C#: Listbox Contextmenu for Listboxitems (WPF)
body: <p>i want for my Listbox in WPF a contextmenu.
  I did it with a contextmenu for the whole listbox, but you can richt-click to get the contextmenu even if you don't click on a item.</p>
  
  <p>I found something at google, but this didn't work out.</p>
  
  <p>I tried something like this:</p>
  
  <pre><code>&lt;ListBox Margin="5" ItemsSource="{Binding}"&gt;
      &lt;ListBox.ItemTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;TextBlock Text="{Binding Name}"&gt;
                  &lt;TextBlock.ContextMenu&gt;
                      &lt;ContextMenu&gt;
                          &lt;MenuItem Header="{Binding Name}" Click="MenuItemName_Click"/&gt;
                          &lt;MenuItem Header="{Binding Capital}"  Click="MenuItemCapital_Click"/&gt;
                          &lt;MenuItem Header="{Binding Population}" Click="MenuItemPopulation_Click"/&gt;
                      &lt;/ContextMenu&gt;
                  &lt;/TextBlock.ContextMenu&gt;
              &lt;/TextBlock&gt;
          &lt;/DataTemplate&gt;
      &lt;/ListBox.ItemTemplate&gt;
  &lt;/ListBox&gt;
  </code></pre>
  
  <p>I tried it with a textblock like in the example, with other elements like in other tutorials, i tired it without and many other things- but nothing worked. No contextmenu for my listbox items :(</p>
  
  <p>later i tried something like this:</p>
  
  <pre><code> &lt;ListBox.ItemTemplate&gt;
       &lt;DataTemplate&gt;
           &lt;ListBoxItem&gt;
               &lt;ListBoxItem.ContextMenu&gt;
                   &lt;ContextMenu&gt;
                       &lt;MenuItem/&gt;
                   &lt;/ContextMenu&gt;
               &lt;/ListBoxItem.ContextMenu&gt;
           &lt;/ListBoxItem&gt;
       &lt;/DataTemplate&gt;
   &lt;/ListBox.ItemTemplate&gt;
  </code></pre>
  
  <p>But it didn't work too.</p>
  
  <p>Can someone give me a hint/working example :)?</p>
  
  <p>thank you</p>