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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:42:09+00:00 2026-05-23T08:42:09+00:00

Is there a way to explicitly capture a click on a TreeView item? Currently,

  • 0

Is there a way to explicitly capture a click on a TreeView item?

Currently, I’m in a position where a TV represents a sort of options menu for users. Ordinarily, I would just use the SelectedItemChanged event on the TV, but there is the possibility of a user re-clicking an item twice in a row which won’t raise this event. I considered the idea of putting an event listener on the stackpanel that contains the items in each node, but the problem is this event fires before a selected item changed on a node. So if you hit the stackpanel, you’ll get the event, but won’t be able to get the associated item. Any ideas on how to get out of this one?

  • 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-23T08:42:10+00:00Added an answer on May 23, 2026 at 8:42 am

    You could handle MouseLeftButtonUp event for the TreeView.

    private void treeView1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
        var selectedItem = treeView1.SelectedItem;
    }
    

    [EDIT]

    You can handle MouseLeftButtonDown, but SelectedItem will not be changed yet at that moment. What you can do is to access e.OriginalSource to find out what element was clicked. I checked the example below with a tree of <TreeViewItem />, so element was TextBlock. If you try the code below change the type casting according to your scenario.

    public MainPage()
    {
        InitializeComponent();
        treeView1.AddHandler(MouseLeftButtonDownEvent, new MouseButtonEventHandler(treeView1_MouseLeftButtonDown), true);
    }
    
    private void treeView1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        var selectedElement = (TextBlock)e.OriginalSource;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to explicitly store my numbers in php as tinyint (1
Is there a way I can indicate to users who have downloaded a blackberry
Is there a way to tell AutoMapper to ignore all of the properties except
Is there any way to make Resharper apply a context action at every applicable
Is there a way to tell PHP to run one last function, or somehow
CLOS has a neat concept of :before, :after, and :around methods. The :before methods
Today I encountered a pecularity which, although probably not really important, nevertheless puzzles me.
I'm using Ayende's NHibernate Linq version 2.1.2, available here , and when I use
I'm generating C# source code which is being built by both VS2010 and Mono's

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.