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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:45:19+00:00 2026-06-18T02:45:19+00:00

Have used the method to set a fullrowselect for TreeViewItems here: Lee Campbell horizontal

  • 0

Have used the method to set a fullrowselect for TreeViewItems
here: Lee Campbell horizontal stretch for treeviewitems

This works well for the top level items.

But there seems to be a problem with the TreeViewItem.Items
collection, which seems not to take the right template.
(I see it is not in the TreeView.Items collection, as the template suggests)

Is there an easy way to derive the subitem style from the parent item style?

How can I describe the style once (for all TreeviewItems) and let the style
be used for all TreeViewItems, whether they are in the TreeView.Items or
in the TreeViewItem.Items collection?

Here is my XAML, some code is from the LeeCampbell example.

<Window x:Class="TreeViewFullRow.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:TreeViewFullRow"
        Title="MainWindow"
        Width="525"
        Height="350">

    <Window.Resources />

    <Grid>

        <TreeView Name="TreeData"
                  Width="236"
                  Height="311"
                  HorizontalAlignment="Left"
                  VerticalAlignment="Top">

            <TreeView.ItemContainerStyle>




                <Style BasedOn="{StaticResource {x:Type TreeViewItem}}" TargetType="TreeViewItem">
                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="TreeViewItem">
                                <StackPanel>
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto" MinWidth="19" />
                                            <ColumnDefinition Width="*" />
                                        </Grid.ColumnDefinitions>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="Auto" />
                                            <RowDefinition />
                                        </Grid.RowDefinitions>
                                        <!--
                                            Note that the following do not work, but I believe the top 2 should?!
                                            <ToggleButton IsChecked="{TemplateBinding IsExpanded}" ClickMode="Press" Name="Expander">
                                            <ToggleButton IsChecked="{TemplateBinding Property=IsExpanded}" ClickMode="Press" Name="Expander">
                                            <ToggleButton IsChecked="{TemplateBinding Path=IsExpanded}" ClickMode="Press" Name="Expander">
                                        -->
                                        <ToggleButton Name="Expander"
                                                      ClickMode="Press"
                                                      IsChecked="{Binding Path=IsExpanded,
                                                                          RelativeSource={RelativeSource TemplatedParent}}">
                                            <ToggleButton.Style>
                                                <Style TargetType="ToggleButton">
                                                    <Setter Property="UIElement.Focusable" Value="false" />
                                                    <Setter Property="FrameworkElement.Width" Value="16" />
                                                    <Setter Property="FrameworkElement.Height" Value="16" />
                                                    <Setter Property="Control.Template">
                                                        <Setter.Value>
                                                            <ControlTemplate TargetType="ToggleButton">
                                                                <Border Width="16"
                                                                        Height="16"
                                                                        Background="#00FFFFFF"
                                                                        Padding="5,5,5,5">
                                                                    <Path Name="ExpandPath"
                                                                          Fill="#00FFFFFF"
                                                                          Stroke="#FF989898">
                                                                        <Path.Data>
                                                                            <PathGeometry Figures="M0,0L0,6L6,0z" />
                                                                        </Path.Data>
                                                                        <Path.RenderTransform>
                                                                            <RotateTransform Angle="135" CenterX="3" CenterY="3" />
                                                                        </Path.RenderTransform>
                                                                    </Path>
                                                                </Border>
                                                                <ControlTemplate.Triggers>
                                                                    <Trigger Property="UIElement.IsMouseOver" Value="True">
                                                                        <Setter TargetName="ExpandPath" Property="Shape.Stroke" Value="#FF1BBBFA" />
                                                                        <Setter TargetName="ExpandPath" Property="Shape.Fill" Value="#00FFFFFF" />
                                                                    </Trigger>
                                                                    <Trigger Property="ToggleButton.IsChecked" Value="True">
                                                                        <Setter TargetName="ExpandPath" Property="UIElement.RenderTransform">
                                                                            <Setter.Value>
                                                                                <RotateTransform Angle="180" CenterX="3" CenterY="3" />
                                                                            </Setter.Value>
                                                                        </Setter>
                                                                        <Setter TargetName="ExpandPath" Property="Shape.Fill" Value="#FF595959" />
                                                                        <Setter TargetName="ExpandPath" Property="Shape.Stroke" Value="#FF262626" />
                                                                    </Trigger>
                                                                </ControlTemplate.Triggers>
                                                            </ControlTemplate>
                                                        </Setter.Value>
                                                    </Setter>
                                                </Style>
                                            </ToggleButton.Style>
                                        </ToggleButton>
                                        <Border x:Name="Bd"
                                                Grid.Column="1"
                                                HorizontalAlignment="Stretch"
                                                Background="{TemplateBinding Panel.Background}"
                                                BorderBrush="{TemplateBinding Border.BorderBrush}"
                                                BorderThickness="{TemplateBinding Border.BorderThickness}"
                                                Padding="{TemplateBinding Control.Padding}"
                                                SnapsToDevicePixels="True">
                                            <ContentPresenter x:Name="PART_Header"
                                                              HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
                                                              Content="{TemplateBinding HeaderedContentControl.Header}"
                                                              ContentSource="Header"
                                                              ContentStringFormat="{TemplateBinding HeaderedItemsControl.HeaderStringFormat}"
                                                              ContentTemplate="{TemplateBinding HeaderedContentControl.HeaderTemplate}"
                                                              ContentTemplateSelector="{TemplateBinding HeaderedItemsControl.HeaderTemplateSelector}"
                                                              SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
                                        </Border>
                                        <ItemsPresenter x:Name="ItemsHost"
                                                        Grid.Row="1"
                                                        Grid.Column="1" />
                                    </Grid>
                                </StackPanel>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="TreeViewItem.IsExpanded" Value="False">
                                        <Setter TargetName="ItemsHost" Property="UIElement.Visibility" Value="Collapsed" />
                                    </Trigger>
                                    <Trigger Property="ItemsControl.HasItems" Value="False">
                                        <Setter TargetName="Expander" Property="UIElement.Visibility" Value="Hidden" />
                                    </Trigger>
                                    <Trigger Property="TreeViewItem.IsSelected" Value="True">
                                        <Setter TargetName="Bd" Property="Panel.Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
                                        <Setter Property="TextElement.Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" />
                                    </Trigger>
                                    <MultiTrigger>
                                        <MultiTrigger.Conditions>
                                            <Condition Property="TreeViewItem.IsSelected" Value="True" />
                                            <Condition Property="Selector.IsSelectionActive" Value="False" />
                                        </MultiTrigger.Conditions>
                                        <Setter TargetName="Bd" Property="Panel.Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
                                        <Setter Property="TextElement.Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
                                    </MultiTrigger>
                                    <Trigger Property="UIElement.IsEnabled" Value="False">
                                        <Setter Property="TextElement.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>




            </TreeView.ItemContainerStyle>

        </TreeView>


        <Button Name="BtnLoad"
                Width="75"
                Height="23"
                Margin="277,12,0,0"
                HorizontalAlignment="Left"
                VerticalAlignment="Top"
                Click="OnBtnLoad"
                Content="Load data" />
    </Grid>
</Window>

This is very easy. In the button click handler I add new Items to the
TreeView. This is the code:

private void OnBtnLoad(object sender, RoutedEventArgs e)
{
    var count = this.TreeData.Items.Count.ToString();
    var parent = new TreeViewItem() { Name = "Name_" + count, Header = "Header_" + count };

    this.TreeData.Items.Add(parent);

    var child0 = new TreeViewItem() { Name = "Name_" + count + "_0", Header = "Header_" + count + "_0" };
    var child1 = new TreeViewItem() { Name = "Name_" + count + "_1", Header = "Header_" + count + "_1" };
    var child2 = new TreeViewItem() { Name = "Name_" + count + "_2", Header = "Header_" + count + "_2" };

    parent.Items.Add(child0);
    parent.Items.Add(child1);
    parent.Items.Add(child2);

    parent.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-18T02:45:20+00:00Added an answer on June 18, 2026 at 2:45 am

    If you put the style further up the visual tree it would affect the items and subitems in the treeview. For example you could put the style in Grid.Resources or in Window.Resources instead of having it in the TreeView.ItemContainerStyle as you do now.

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

Sidebar

Related Questions

I have used the method described here to localize my data annotation messages and
I have written a login form, in this I have used, form and method
Excuse my limited knoweldge here. In the past I have used Steve Sanderson's method
All, I have a method that returns a List. This method is used to
I have a problem when call applet method from javascript.. I used this function
I have used MEF to load in external XAPs, this works great. But when
I have used beans:profiles in my xml like this: <beans profile=dev> <bean id=dataSource destroy-method=close
I have the following method (used to generate friendly error messages in unit tests):
I have a gridview for which JQuery drag and drop method is used to
I have created a method to check if the keyboard is used in an

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.