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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:20:54+00:00 2026-05-28T20:20:54+00:00

I am trying to change SelectedItem template in TreeView. I wrote simple container style

  • 0

I am trying to change SelectedItem template in TreeView.
I wrote simple container style and change item template in Style.Triggers as described

[1]: How do I highlight a treeview selected item with some color? or

[2]: WPF TreeView: How to style selected items with rounded corners like in Explorer but it doesn’t work.

Then I created a new project and created TreeView with a simple style and template

<TreeView>
        <TreeViewItem Header="Item1" />
        <TreeViewItem Header="Item2" />
        <TreeViewItem Header="Item3"/>

        <TreeView.Resources>
            <DataTemplate DataType="{x:Type TreeViewItem}" x:Key="selectedTemplate">
                <StackPanel Height="25">
                    <TextBlock Text="SelectedItem"/>
                </StackPanel>
            </DataTemplate>
        </TreeView.Resources>

        <TreeView.ItemContainerStyle>
            <Style TargetType="TreeViewItem">
                <Style.Triggers>
                    <Trigger Property="IsSelected" Value="True">
                        <Setter Property="FontWeight" Value="Bold"/>
                        <Setter Property="FontStyle" Value="Italic"/>
                        <Setter Property="Foreground" Value="Red"/>
                        <Setter Property="Background" Value="Green"/>
                        <Setter Property="ItemTemplate" Value="{StaticResource selectedTemplate}"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </TreeView.ItemContainerStyle>
    </TreeView>

So, then I selected TreeViewItem in tree view FontWeight, FontStyle and Foreground are changed, but Background and ItemTemplate doesn’t changed.

Result: here

Could you explain this strange behavior?

  • 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-28T20:20:55+00:00Added an answer on May 28, 2026 at 8:20 pm

    ItemTemplate property affects children elements and not the item itself. And background is set to default selection background for Border that adornes the content, so the green color underneath is not visible.
    You can achieve your goals like this:

     <TreeView>
            <TreeViewItem Header="Item1" />
            <TreeViewItem Header="Item2" />
            <TreeViewItem Header="Item3"/>
    
            <TreeView.Resources>
                <ControlTemplate TargetType="{x:Type TreeViewItem}" x:Key="selectedTemplate">
                    <StackPanel Height="25">
                        <TextBlock Text="SelectedItem" Background="{TemplateBinding Background}" />
                    </StackPanel>
                </ControlTemplate>
            </TreeView.Resources>
    
            <TreeView.ItemContainerStyle>
                <Style TargetType="TreeViewItem">
                    <Style.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="FontWeight" Value="Bold"/>
                            <Setter Property="FontStyle" Value="Italic"/>
                            <Setter Property="Foreground" Value="Red"/>
                            <Setter Property="Background" Value="Green"/>
                            <Setter Property="Template" Value="{StaticResource selectedTemplate}"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </TreeView.ItemContainerStyle>
        </TreeView>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm trying to get a link from a image map to change selected item
I'm trying to change the background of the selected item in a WPF ListBox.
I am trying to get a cell value from the selected item of a
I cannot seem to figure out how to dynamically change the selected item in
Trying to add handling for when the selected item changes in a drop-down. However,
I am trying to delete the selected item from a ListView and the Problem
I'm trying to set a variable to the value of the selected item in
I am trying to get the text of the selected item of a listbox.
I am trying to change the Control template on a ListBoxItem when It is
I have some simple example WinForms code which I am trying to translate into

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.