title: How to Identify button for list item
body: <p>How do i access the object UserNames, that is bound to the list??</p>
  
  <p>What i did so far:</p>
  
  <p>Item of the list is object in my case:</p>
  
  <pre><code> new List&lt;UserNames&gt;();
   this.users.Add(new UserNames() {Id = 1, UserName = "name 1"});
  </code></pre>
  
  <p>I am using data template for which i have label and button.</p>
  
  <p>My List is as follows:</p>
  
  <pre><code>&lt;ListBox Grid.Column="1" Grid.Row="1" Name="listBox1" ItemsSource="{Binding}" SelectedValuePath="Id"&gt;
              &lt;ListBox.ItemTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;WrapPanel Orientation="Vertical"&gt;
                          &lt;StackPanel&gt;
                              &lt;Label Content="{Binding UserName}"  /&gt;
                          &lt;/StackPanel&gt;
                          &lt;StackPanel Name="ButtonStackPanel"&gt;
                              &lt;Button Name="MyButton" Content="Click Me" Click="MyButton_Click"&gt;
  
                              &lt;/Button&gt;
                          &lt;/StackPanel&gt;
                      &lt;/WrapPanel&gt;
                  &lt;/DataTemplate&gt;
              &lt;/ListBox.ItemTemplate&gt;
          &lt;/ListBox&gt;
  </code></pre>
  
  <p>Where my method for Button is. As you can see i did try to utilise the parent option, but without sucess</p>
  
  <pre><code> private void MyButton_Click(object sender, RoutedEventArgs e)
          {
              //StackPanel panel = (StackPanel)((Button)sender).Parent;
              //WrapPanel wrapPanel = (WrapPanel) panel.Parent;
              //ListItem listItem = (ListItem) wrapPanel.Parent;
              //ListBox box = (ListBox) listItem.Parent;
              //UserNames itemToReport = (UserNames) (box.SelectedItem);
              //MessageBox.Show(itemToReport.UserName);
  
  
          }
  </code></pre>