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

  • Home
  • SEARCH
  • 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 7694359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:18:06+00:00 2026-05-31T21:18:06+00:00

The SelectedItemChanged event and SelectedItem property of TreeView do not occur when the TreeViewItem

  • 0

The SelectedItemChanged event and SelectedItem property of TreeView do not occur when the TreeViewItem is an input control like Textbox. The sample code below illustrates the problem by placing a breakpoint in TreeView SelectedItemChanged event. This breakpoint will fire when “String Header” is selected, but not “Textbox Header”.

I assume that the Textbox or RichTextbox (My real application) is eating some vital bubbling event. How can I get the TreeView SelectedItem to behave for a TextBox as it would for control like Label?

Note: If I can solve this issue I will need to two-way bind to SelectedItem as I am using MVVM and MEF. SelectedItem is readonly which is problem, which I plan to solve with ( http://silverscratch.blogspot.com/2010/11/two-way-binding-on-treeviewselecteditem.html ). I thought this related link might help someone.

XAML:

<TreeView SelectedItemChanged="TreeView_SelectedItemChanged">
    <TreeViewItem>
        <TreeViewItem.Header>
            <TextBox>
                Textbox Header
            </TextBox>
        </TreeViewItem.Header>
    </TreeViewItem>
    <TreeViewItem>
        <TreeViewItem.Header>
            String Header
        </TreeViewItem.Header>
    </TreeViewItem>
</TreeView>

Code Behind:

    private void TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
    {
        // Breakpoint will fire when "String Header" Selected
        // !!! Breakpoint does not fire when Textbox Selected
        var newValue = e.NewValue;
        var oldValue = e.OldValue;
    }

Thanks,

  • 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-31T21:18:07+00:00Added an answer on May 31, 2026 at 9:18 pm

    You should catch GotFocus event on your TreeView :

    <TreeView SelectedItemChanged="TreeView_SelectedItemChanged"
              GotFocus="UIElement_OnGotFocus">
       <TreeViewItem>
          <TreeViewItem.Header>
              <TextBox>Textbox Header</TextBox>
           </TreeViewItem.Header>
       </TreeViewItem>
       <TreeViewItem>
            <TreeViewItem.Header>String Header</TreeViewItem.Header>
       </TreeViewItem>
     </TreeView>
    
    private void UIElement_OnGotFocus(object sender, RoutedEventArgs e)
    {
        TreeViewItem item = UIHelpers.TryFindParent<TreeViewItem>   
                               ((DependencyObject) e.OriginalSource);
        if (item != null)
              item.IsSelected = true;
    }
    

    The implementation of TryFindParent you may found here:
    https://stackoverflow.com/a/4838168/1088908

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

Sidebar

Related Questions

I have TreeView control and I want to bind tree nodes' IsExpanded property to
I have a WPF TreeView which triggers a SelectedItemChanged event. Whenever I select an
In XAML I have: <sdk:TreeView x:Name=navigationTreeView Grid.Column=0 Grid.Row=1 SelectedItemChanged=TreeView_SelectedItemChanged> <sdk:TreeView.ItemContainerStyle> <Style TargetType=sdk:TreeViewItem> <Setter Property=IsExpanded
When my DataGrid populates on the TreeView's SelectedItemChanged event it finds the objects and
The following code throws an exception: <TreeView ItemsSource={Binding TreeRootInstance} x:Name=Htree ItemTemplate=CellTemplate SelectedItemChanged=HTree_OnSelectedItemChanged KeyDown=HTree_KeyDown> <TreeView.Resources>
I have a TreeView control from System.Windows.Controls on MainPage. <controls:TreeView x:Name=Tree SelectedItemChanged=Tree_SelectedItemChanged /> MainPage
I have a control with this xaml: <Controls:TreeView x:Name=MachineGroupsTree Style={StaticResource MachineGroupStyle} > <i:Interaction.Triggers> <i:EventTrigger
I have at treeview TextBox, and I want convert my Enum: <TextBlock TextAlignment=Justify VerticalAlignment=Center
I've got a TreeView which contains a number of TreeViewItems . Each TreeViewItem contains
This sounds like a tricky question... let me ellaborate... I have a treeView. When

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.