title: Find parentitem in wpf-treeview
body: <p>I hoped the answer to <a href="https://stackoverflow.com/questions/672005/c-find-treeviewitem-to-drop-data">my previous question</a> whould help me with this one, but it didn't. The initial situation is pretty much the same:</p>
  
  <pre><code>&lt;TreeView ItemsSource="{Binding Groups}" Name="tvGroups" AllowDrop="True"&gt;
            &lt;TreeView.ItemTemplate&gt;
                      &lt;HierarchicalDataTemplate ItemsSource="{Binding Participants}"&gt;
                            &lt;StackPanel Orientation="Horizontal" Drop="tvDrop" Tag="{Binding .}"&gt;
                                 &lt;TextBlock Text="{Binding Name}" /&gt;
                                 &lt;Button Tag="{Binding .}" Click="Button_Click_2"&gt;
                                      &lt;Image Source="Resources/cross.png" /&gt;
                                  &lt;/Button&gt;
                            &lt;/StackPanel&gt;
                            &lt;HierarchicalDataTemplate.ItemTemplate&gt;
                                &lt;DataTemplate&gt;
                                    &lt;StackPanel Orientation="Horizontal" &gt;
                                         &lt;TextBlock Text="{Binding Alias}" /&gt;
                                         &lt;Button Tag="{Binding .}" Name="btnDeleteParticipants" Click="btnParticipants_Click" &gt;
                                              &lt;Image Source="Resources/cross.png" /&gt;
                                         &lt;/Button&gt;
                                    &lt;/StackPanel&gt;
                                &lt;/DataTemplate&gt;
                            &lt;/HierarchicalDataTemplate.ItemTemplate&gt;
                      &lt;/HierarchicalDataTemplate&gt;
            &lt;/TreeView.ItemTemplate&gt;
  &lt;/TreeView&gt;
  </code></pre>
  
  <hr>
  
  <pre><code> private void btnParticipants_Click(object sender, RoutedEventArgs e)//Probanten aus Gruppe entfernen
          {
              Participant p = ((sender as Button).Tag as Participant);
              if (p == null) return;
              //TODO: Raus bekommen in welcher Gruppe ich löschen will
  
          }
  </code></pre>
  
  <p>I want to remove <code>Participant p</code> from a <code>Group</code> by clicking the button(btnDeleteParticipants). I tried something like this one:</p>
  
  <pre><code>Control c = sender as Control;
  while (!(c is TreeViewItem))
       c = (c.Parent) as Control;
  </code></pre>
  
  <p>But this didn't work (don't ask why, I'm not sure). I could find the <code>Group</code> by checking if it contains the <code>Participant</code>(bound to <code>btnDeleteParticipants.Tag</code>), but this would disallow participants to be in more than 1 group.
  So, any ideas how to get the right <code>Group</code>?</p>
  
  <p><strong>Edit:</strong> </p>
  
  <pre><code>Groups = new ObservableCollection&lt;Group&gt;();
  Participants = new ObservableCollection&lt;Participant&gt;();
  </code></pre>