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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:34:55+00:00 2026-05-22T16:34:55+00:00

I have a TreeView bound to a hierarchy consisting of several different classes via

  • 0

I have a TreeView bound to a hierarchy consisting of several different classes via HierarchicalDataTemplates. When an item in the tree is selected, the SelectedItemChanged event of course happily bubbles upwards through the parent items, as it should. What it should not do, but still does, is happily keeping on bubbling after I set e.Handled to true.

The event will still fire on the parent item, and the RoutedPropertyChangedEventArgs will look exactly like it was the parent item that was selected; even the OriginalSource property will point to the parent item, not the one that was originally selected. e.Handled will of course be false.

Pretty much the same question was asked here, but I’m not using EventAggregator or CAL, and the workaround found here doesn’t help much because I am not specifically after a mouse event.

Is there any way to precisely get the item that was actually selected or to forcefully stop the bubbling madness (without resorting to a very violent and unethical hack using global variables that I can think of)?

Thanks for any insights.

  • 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-22T16:34:56+00:00Added an answer on May 22, 2026 at 4:34 pm

    After reading Rick’s answer, I talked to a co-worker who it turned out had had the same problem before. I tried various things in my application (finding: the TreeViewItem.Selected event behaves exactly the same wrong way) and a test project and found that in the test app the events were firing exactly as one would expect it. So there had to be a significant difference in the surroundings (the XAML and ViewModel classes were nearly identical) that led to this difference in behavior – and the culprit looks to be COM, precisely hosting the WPF controls in a COM application.

    My colleague’s application is a Word extension using VSTO, while mine is a VSPackage for Visual Studio 2010 – and both Word and VS2010 are still native code for the most part. My test application, on the other hand, is of course a small plain WPF project. I added a WinForms form with an ElementHost to it that in turn hosted a UserControl with a TreeView, but that still worked as it should, so to me it really looks like the host COM application is in some way interfering with the events raised on the TreeView and TreeViewItems.

    Luckily, my colleague found/googled a solution that will do for the time being – after you’re done with the actual reaction to the event, at the end of the event handler method, again set the TreeViewItem as selected and focus it:

    item.Focus();
    item.IsSelected = true;
    

    We don’t understand why, but this will stop the items from being wrongfully re-selected (this is obviously not really a bubbling event in the WPF sense).

    Thanks again to Rick for his nudge towards keeping TreeView and TreeViewItem events separate in my mind.

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

Sidebar

Related Questions

I have a treeview that is bound to a collection and each item in
I have a treeview (winforms) which have different item types on it. I have
I have a treeview that is bound to a database table. Each treeview item
I have a TreeView that is bound to a tree of ViewModel instances. The
I have TreeView which contains different item types. Item Styles are defined over a
In my WPF application, I have a treeview. This treeview is bound to a
I have a TreeView that is bound to a XmlDataSource control. I've added some
I have bound a TreeView to an XMLDataProvider. The TreeView displays the data as
I have a TreeView that is bound to a collection class that I have
I have a TreeView bound to an XmlDataProvider . The name of a node

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.