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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:16:06+00:00 2026-06-07T02:16:06+00:00

So, I create a TreeViewItem (parentNode), and I add TreeViewItems into the parentNode TreeViewItem.

  • 0

So, I create a TreeViewItem (parentNode), and I add TreeViewItems into the parentNode TreeViewItem. I then add a MouseButtonEventHandler to the parentNode, and now all the TreeViewItems inside parentNode have the MouseButtonEventHandler. I’ve run the debugger to see if I have code that was accidentally written to add the MouseButtonHandler, but there isn’t…

Edit: I did additional tests, and it even goes two levels down. Is there a way to isolate eventhandlers to only the specific node and not its children and/or parents?

public newClass() {
    TreeViewItem parent = new TreeViewItem();

    TreeViewItem childOne = new TreeviewItem();
    addExpandClickListener(childOne);

    TreeViewItem childTwo = new TreeviewItem();
    TreeViewItem childThree = new TreeViewItem();


    childTwo.Items.Add(childThree);
    childOne.Items.Add(childTwo);
    parent.Items.Add(childOne);
    TreeViewObject.Items.Add(parent);
}

private void addExpandClickListener(TreeViewItem item) { item.MouseLeftButtonUp += new MouseButtonEventHandler(item_MouseClick); }


private void item_MouseClick(object sender, MouseButtonEventArgs e) {
    // Define click event as handled
    e.Handled = true;
    if(sender != e.Source) return;
    // Handle click event
    TreeViewItem root = (TreeViewItem)sender;
    if(root.IsExpanded == true) CollapseRecursive(root);
    else root.IsExpanded = true;
    //else root.ExpandSubtree();
    ViewTree.Items.Refresh();
}
  • 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-06-07T02:16:08+00:00Added an answer on June 7, 2026 at 2:16 am

    The area of the parentNode includes the areas of the children. Think of overlapping rectangles. If you only want to have a click to work for the text part, you’ll either have to supply your own DataTemplate or use the visual tree to find the header and apply the click to that.

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

Sidebar

Related Questions

CREATE TABLE #TEMPTABLE ( requestTime datetime2, NoOfSessions integer ) INSERT INTO #TEMPTABLE select convert(nvarchar(16),
Create any application in Delphi XE2 and press F1 to run help system. You'll
I am trying to create a TreeView from the Silverlight TreeView control. I have
Problem I have a Silverlight 5 application using the treeview from the SDK. Now
create or replace trigger insert_test_id before insert on test where(test.name='Ash') begin insert into test(s_no)
Create one listview and add the item in listview like listview1.Items.Add(new ListViewItem(hello i am
Create default iPad split view based apps from template from xcode 4, then we
I have a TreeView setup so that each TreeViewItem has right-click context menu applied
I'm trying to create a new TreeViewItem with a control in it like: <TreeViewItem>
I'm currently using Castle Windsor v2.5.1 and running into a few issues. I have

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.