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

I have a TreeView implemented in WPF that is bound to some XML data
In a WPF application, I have correctly bound a DataTemplate to an XML node
I have a fairly complex tree of data which I'm displaying in a WPF
I have a WPF DataGrid that increases in height when I add data to
I have a tree in WPF that has no root node, but has defined
I am working on an interactive WPF graph/tree tool and have nodes and links
I have three tree view controls which house different (but mostly similar data), as
I am trying to create Below parent child structur using WPF tree. Tree ->Parent
I have a wpf treeview bound to collection. The model collection is of type:
I have WPF form with DataGrid. New columns can be added to the datagrid

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.