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 3348970
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:36:27+00:00 2026-05-18T01:36:27+00:00

I have a WPF tree (bound to XML data). An excerpt is given below:

  • 0

I have a WPF tree (bound to XML data). An excerpt is given below:

(Well shoot, i can’t post a picture because my reputation isn’t high enough yet. If my rep gets up to 10, I’ll post it. Other wise just imagine a regular tree view with some plus and minus icons at a few of items on various levels)

And because I need to have special operations at certain levels, I’ve inserted some icons at certain levels of the tree. Well, actually I’ve entered them at all levels of the tree like and just just chose to show them on certain levels using triggers. This is my XAML Code for this:

<HierarchicalDataTemplate ItemsSource="{Binding Path=Elements}" x:Key="ViewEditTreeTemplate">
<StackPanel Orientation="Horizontal" Margin="1">
     <Label x:Name="ElementHeaderLabel" Height="16" Padding="1" VerticalContentAlignment="Center" FontSize="11" FontWeight="Normal">
          <MultiBinding Converter="{StaticResource ElementHeader}">
                <Binding Path="Name.LocalName"/>
                <Binding Path="Attribute[name].Value" />
          </MultiBinding>
     </Label>

     <Image x:Name="AddButton" Source="Images/button_add_icon.png"  Visibility="Collapsed" MouseLeftButtonUp="AddButton_MouseLeftButtonUp" />
     <Image x:Name="DeleteButton" Source="Images/button_delete_icon.png"  Visibility="Collapsed" MouseLeftButtonUp="DeleteButton_MouseLeftButtonUp" />
     <Image x:Name="EditButton" Source="Images/button_edit_icon.png"  Visibility="Collapsed" MouseLeftButtonUp="EditButton_MouseLeftButtonUp"/>
</StackPanel>

<HierarchicalDataTemplate.Triggers>


     <!-- Showing aditional buttons for RFFs list -->
     <DataTrigger Binding="{Binding Path=Name.LocalName}" Value="RFFs">
          <Setter TargetName="AddButton" Property="Visibility" Value="Visible"/>
          <Setter TargetName="DeleteButton" Property="Visibility" Value="Visible"/>
     </DataTrigger>

     <!-- Showing aditional buttons for RFF -->
     <DataTrigger Binding="{Binding Path=Name.LocalName}" Value="RFF">
          <Setter TargetName="EditButton" Property="Visibility" Value="Visible"/>
     </DataTrigger>

     <!-- Showing aditional buttons for Stations list -->
     <DataTrigger Binding="{Binding Path=Name.LocalName}" Value="Stations">
          <Setter TargetName="AddButton" Property="Visibility" Value="Visible"/>
          <Setter TargetName="DeleteButton" Property="Visibility" Value="Visible"/>

     </DataTrigger>

     <!-- Showing aditional buttons for AdjacentRegionNames list -->
     <DataTrigger Binding="{Binding Path=Name.LocalName}" Value="AdjacentRegionNames">
          <Setter TargetName="AddButton" Property="Visibility" Value="Visible"/>
          <Setter TargetName="DeleteButton" Property="Visibility" Value="Visible"/>

     </DataTrigger>
</HierarchicalDataTemplate.Triggers>

My problem is this. I’ve added an event handler to those icons (AddButton, DeleteButton, and EditButton), but when I get inside the event handling routine, I have no idea which node the user was on when they clicked on the node. Can i pass anything to that event handler MouseLeftButtonUp(…) or is there some way i can figure out where the user was when they clicked my image?

  • 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. Editorial Team
    Editorial Team
    2026-05-18T01:36:27+00:00Added an answer on May 18, 2026 at 1:36 am

    The TreeViewItem which the user clicked is accessible through the event args:

    private void TreeView_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
            {
                TreeViewItem ti = (TreeViewItem)e.Source;
                //do stuff here
            }
    

    If the item is not actually a “TreeViewItem” you should be able to cast it to it’s type in order to work with it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a WPF application, I have correctly bound a DataTemplate to an XML node
I have WPF ListBox which is bound to a ObservableCollection, when the collection changes,
I have a WPF ListView that is bound to a BindingList<T>. The binding works
I have a WPF ListView which repeats the data vertically. I cannot figure out
I have a WPF UI that is bound to an object. I'm using a
In my WPF application, I have a treeview. This treeview is bound to a
I am working on an interactive WPF graph/tree tool and have nodes and links
I have a WPF project and I'm trying to setup a NAnt build script
I have a WPF application in VS 2008 with some web service references. For
I have a WPF Window which has a among other controls hosts a Frame.

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.