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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:36:09+00:00 2026-05-12T17:36:09+00:00

I want every clickable TreeViewItem to execute TreeViewItem_MouseLeftButtonDown , is there a way to

  • 0

I want every clickable TreeViewItem to execute TreeViewItem_MouseLeftButtonDown, is there a way to put this in the style so I don’t have to define it everywhere. I could run through all children in code behind but I would think there would be an easier way to do it in a style.

The following code gives me:

Cannot find the Style Property
‘PreviewMouseLeftButtonDown’ on the
type
‘System.Windows.Controls.TreeViewItem’.

<Window x:Class="TestClickTree2343.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    WindowStartupLocation="CenterScreen"
    Title="Window1" Height="300" Width="300">
    <Window.Resources>
        <Style TargetType="TreeViewItem">
            <Setter Property="IsExpanded" Value="True" />
            <Setter Property="Foreground" Value="#aaa" />
        </Style>
        <Style x:Key="TreeViewItemClickableStyle" TargetType="TreeViewItem">
            <Setter Property="Cursor" Value="Hand" />
            <Setter Property="Foreground" Value="#000" />
            <Setter Property="PreviewMouseLeftButtonDown" Value="TreeViewItem_MouseLeftButtonDown" />
        </Style>
    </Window.Resources>

    <StackPanel>
        <TreeViewItem Header="Files">
            <TreeViewItem Header="File 1">
                <TreeViewItem Header="Part 1">
                    <TreeViewItem Style="{StaticResource TreeViewItemClickableStyle}" Header="Paragraph 1"/>
                    <TreeViewItem Header="Paragraph 2"/>
                </TreeViewItem>
            </TreeViewItem>
        </TreeViewItem>
    </StackPanel>
</Window>
  • 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-12T17:36:10+00:00Added an answer on May 12, 2026 at 5:36 pm

    Use SelectedItemChanged in TreeView instead:

    XAML:

    <TreeView  SelectedItemChanged="TreeView_SelectedItemChanged" BorderThickness="0">
        <TreeViewItem 
            Tag="File1" 
            Style="{StaticResource TreeViewItemClickableStyle}" 
            Header="File 1">
    
            <TreeViewItem Header="Part 1">
    
                <TreeViewItem Header="Paragraph 1"/>
    
                <TreeViewItem 
                    Tag="Paragraph1" 
                    Style="{StaticResource TreeViewItemClickableStyle}" 
                    Header="Paragraph 2"/>
    
                <TreeViewItem Header="Paragraph 3"/>
                <TreeViewItem Header="Paragraph 4"/>
                <TreeViewItem Header="Paragraph 5"/>
    
            </TreeViewItem>
        </TreeViewItem>
    </TreeView>
    

    Code-behind:

    private void TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
    {
        TreeViewItem treeViewItem = ((TreeView)sender).SelectedItem as TreeViewItem;
        if (treeViewItem.Tag != null)
        {
            string tag = treeViewItem.Tag.ToString();
            MessageBox.Show(String.Format("You clicked the tree item: {0}", tag));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table and I want every row to be clickable. Right now,
I have a Translation table and I want every update to it to automatically
Is this good OO Design assuming you want every inheriting class to be a
I have an php website with login form and I want every visitors can
In my activity there is a toggle button. I want every time you change
I have a problem, storing instances of a viewController object. I want every user
I have code like that 010200345 i want split every first three digit please
Let's say I have a class of 30 students and want generate every possible
I want to have a base colour, say 0x0066FF and I want every iteration
We have two domains, example.com and example.net · We want every request to example.net

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.