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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:16:00+00:00 2026-06-01T16:16:00+00:00

I have the following treeview defined in my xaml: <TreeView Name=PST_TreeView Grid.Row=0 Grid.Column=0 Width=Auto

  • 0

I have the following treeview defined in my xaml:

        <TreeView Name="PST_TreeView"
              Grid.Row="0"
              Grid.Column="0"
              Width="Auto"
              Height="Auto"
              HorizontalAlignment="Stretch"
              VerticalAlignment="Stretch"
              ItemsSource="{Binding SitesCollection}"
              ItemTemplate="{StaticResource SitesTemplate}"
              Style="{StaticResource TreeViewStyleBasic}" />

With Resource bindings targeting my resources file:

    <Style x:Key="TreeViewStyleBasic" TargetType="TreeView">
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="BorderBrush" Value="{DynamicResource TitleBarButtons_BorderBrush}" />
    <Setter Property="BorderThickness" Value="0 0 2 0" />
</Style>

<Style x:Key="TreeViewItemStyle_CatNodes" TargetType="{x:Type TextBlock}">
    <Setter Property="Foreground" Value="Snow" />
    <Setter Property="FontFamily" Value="Calibri" />
    <Setter Property="FontSize" Value="16" />
    <Setter Property="FontWeight" Value="Normal" />
    <Setter Property="TextAlignment" Value="Left" />
</Style>

<Style x:Key="TreeViewItemStyle_ChildNodes" TargetType="{x:Type TextBlock}">
    <Setter Property="Foreground" Value="Snow" />
    <Setter Property="FontFamily" Value="Calibri" />
    <Setter Property="FontSize" Value="14" />
    <Setter Property="FontWeight" Value="Normal" />
    <Setter Property="FontStyle" Value="Italic" />
    <Setter Property="TextAlignment" Value="Left" />
</Style>

<DataTemplate x:Key="VolumeInfoDataTemplate">
    <StackPanel Orientation="Horizontal">
        <TextBlock Width="{TemplateBinding Width}"
                   Height="{TemplateBinding Height}"
                   Margin="5"
                   Style="{DynamicResource TreeViewItemStyle_ChildNodes}"
                   Text="{Binding VolumeName}" />
    </StackPanel>
</DataTemplate>

<HierarchicalDataTemplate x:Key="SitesTemplate"
                          ItemsSource="{Binding VolumesList}"
                          ItemTemplate="{StaticResource VolumeInfoDataTemplate}">
    <StackPanel Orientation="Horizontal">
        <TextBlock Width="{TemplateBinding Width}"
                   Height="{TemplateBinding Height}"
                   Margin="5"
                   Style="{DynamicResource TreeViewItemStyle_CatNodes}"
                   Text="{Binding SiteName}" />
    </StackPanel>
</HierarchicalDataTemplate>

The xaml and resource look ups above work find and as expected.

How might I employ triggers to extend my style definitions to say for example handle the ‘IsSelected’ event so that the selected tree node will have a slate grey border and a light grey background?

RESEARCH: Kind of thing I am going for.

UPDATE: There is no IsSelected property on the TreeView, however TreeViewItem does has one defined.

  • 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-01T16:16:02+00:00Added an answer on June 1, 2026 at 4:16 pm

    Try this:

      <DataTemplate x:Key="VolumeInfoDataTemplate"> 
            <StackPanel Orientation="Horizontal"> 
                <TextBlock Width="{TemplateBinding Width}" 
                           Height="{TemplateBinding Height}" 
                           Margin="5" 
                           Style="{DynamicResource TreeViewItemStyle_ChildNodes}" 
                           Text="{Binding VolumeName}"
                           Name="Tb" /> 
            </StackPanel> 
            <DataTemplate.Triggers>
                 <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource    AncestorType=TreeViewItem}}" Value="True">
                      <Setter TargetName="Tb" Property="Background" Value="LightGray"/>
                 </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following XAML: <TreeView> <TreeViewItem ItemsSource={Binding} Header=TopMost IsExpanded=True> <TreeViewItem.ItemTemplate> <DataTemplate> <TreeViewItem> <TreeViewItem.Header>
Let's pretend I have the following xaml... <UserControl.Resources> <local:ViewModel x:Name=viewModel /> <local:LoadChildrenValueConverter x:Name=valueConverter />
I have the following XAML code as part of a custom control: <telerik:RadTreeView x:Name=treeModules>
I have the following XAML: <UserControl x:Class=EMS.Controls.Dictionary.TOCControl xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:vm=clr-namespace:EMS.Controls.Dictionary.Models xmlns:diagnostics=clr-namespace:System.Diagnostics;assembly=WindowsBase x:Name=root > <TreeView
If I have the following data template for a TreeView , what do I
Lets say I have the following data: <XmlDataProvider x:Key=Values> <x:XData> <folder name=C:> <folder name=stuff
I have a treeview with checkboxes and I have the following handler for the
I have a following problem. I have some items in my treeview which are
I have one class called Holder (holder.cs) that contain the following: string name; List<String>
i have the following xml structure and want to add it to a treeview.

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.