Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 165491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:55:49+00:00 2026-05-11T11:55:49+00:00

I hoped the answer to my previous question whould help me with this one,

  • 0

I hoped the answer to my previous question whould help me with this one, but it didn’t. The initial situation is pretty much the same:

<TreeView ItemsSource='{Binding Groups}' Name='tvGroups' AllowDrop='True'>           <TreeView.ItemTemplate>                     <HierarchicalDataTemplate ItemsSource='{Binding Participants}'>                           <StackPanel Orientation='Horizontal' Drop='tvDrop' Tag='{Binding .}'>                                <TextBlock Text='{Binding Name}' />                                <Button Tag='{Binding .}' Click='Button_Click_2'>                                     <Image Source='Resources/cross.png' />                                 </Button>                           </StackPanel>                           <HierarchicalDataTemplate.ItemTemplate>                               <DataTemplate>                                   <StackPanel Orientation='Horizontal' >                                        <TextBlock Text='{Binding Alias}' />                                        <Button Tag='{Binding .}' Name='btnDeleteParticipants' Click='btnParticipants_Click' >                                             <Image Source='Resources/cross.png' />                                        </Button>                                   </StackPanel>                               </DataTemplate>                           </HierarchicalDataTemplate.ItemTemplate>                     </HierarchicalDataTemplate>           </TreeView.ItemTemplate> </TreeView> 

 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          } 

I want to remove Participant p from a Group by clicking the button(btnDeleteParticipants). I tried something like this one:

Control c = sender as Control; while (!(c is TreeViewItem))      c = (c.Parent) as Control; 

But this didn’t work (don’t ask why, I’m not sure). I could find the Group by checking if it contains the Participant(bound to btnDeleteParticipants.Tag), but this would disallow participants to be in more than 1 group. So, any ideas how to get the right Group?

Edit:

Groups = new ObservableCollection<Group>(); Participants = new ObservableCollection<Participant>(); 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T11:55:50+00:00Added an answer on May 11, 2026 at 11:55 am

    Are Groups and Participants ObservableCollection objects?

    Try using this:

    static TObject FindVisualParent<TObject>(UIElement child) where TObject : UIElement {   if (child == null)   {     return null;   }    UIElement parent = VisualTreeHelper.GetParent(child) as UIElement;    while (parent != null)   {     TObject found = parent as TObject;     if (found != null)     {       return found;     }     else     {       parent = VisualTreeHelper.GetParent(parent) as UIElement;     }   }    return null; } 

    Also, try using the DataContext to get the participant and set the Tag to the TemplatedParent.

    <Button Tag='{Binding RelativeSource={RelativeSource TemplatedParent}}' /> 

    Then on click

    private void btnParticipants_Click(object sender, RoutedEventArgs e) {   var button = sender as Button;   var p = button.DataContext as Participant;   if (p == null) return;    var t= FindVisualParent<TreeViewItem>(button); // get the Participants TreeViewItem   if (t == null) return;   var groupTreeItem = FindVisualParent<TreeViewItem>(t);  // get the groups TreeViewItem   if (groupTreeItem == null) return;   var group = groupTreeItem.DataContext as Group;   group.Participants.Remove(p); } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think I already know the answer to this one, but i hope maybe
They brush the subject in this thread, but it does not really answer much:
I Posted the background to this question a few days ago.. but the answer
I have asked a question like this before, and the answer was great but
I have little bit longer question for you - but hope answer will be
I'm sure I've seen this before and know the answer to it but after
In my previous question I got an excellent answer that helped me detect where
I hope I get an answer to my question this time, I already posted
Maybe a 1000 times asked question but I could not find and sophisticated answer.
Ok, I've read all kinds of similar questions but I didn't find an answer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.