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 WCF Web Api Restful webservice. I want every single service call
I want to run a code on every postback on client-side. Is there an
I want to make an array with every card in the deck, so it
Basically what i want is this but in a for-loop.. echo `date +'['%H':'%M':'%S']'` -
I was wondering about how could I have in Django an exclusive Checkbox and
I have a string, with characters a-z , A-Z , 0-9 , ( ,
I want to subscribe to the AppDomain.CurrentDomain.UnhandledException event to catch any errors as im
I want to insert alot of rows into a table that generates the keys
Suppose I wanted to echo every executable inside the %programfiles% folder cd %programfiles% for
What I want to do is just display a few specific columns from my

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.