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

The Archive Base Latest Questions

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

Can someone tell me how I can template a treeview control so that it

  • 0

Can someone tell me how I can template a treeview control so that it doesn’t look like a tree? Basically, I want to remove the indents at various levels as well as the +/- that allow for expansion and collapse.

The actual requirement is that I have a hierarchical data template that is bound to an object collection that is recursive in nature. And I want to display these objects on screen in a flat manner. The best solution would be to get the hierarchical data template to work with an itemscontrol. But sadly, i believe that the itemscontrol does not understand hierarchical templates. So I am forced to use a treeview control and strip all the “tree” features.

Any suggestions will be mighty helpful..

  • 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-12T16:09:00+00:00Added an answer on May 12, 2026 at 4:09 pm

    You need to modify the TreeViewItem’s template. I already did it for you, just copy/paste code below in your Window. Although I extremely recommend you study ControlTemplates and how to modify them since if you’re gonna be using WPF. It’s EXTREMELY useful.

    Here you go:

    <Window.Resources>
            <SolidColorBrush x:Key="WindowBackgroundBrush" Color="#FFF" />
            <SolidColorBrush x:Key="SolidBorderBrush" Color="#888" />
            <SolidColorBrush x:Key="GlyphBrush" Color="#444" />
    
            <!-- TreeView -->           
            <Style x:Key="{x:Type TreeView}" TargetType="TreeView">
                <Setter Property="OverridesDefaultStyle" Value="True" />
                <Setter Property="SnapsToDevicePixels" Value="True" />
                <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
                <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="TreeView">
                            <Border 
                                Name="Border" 
                                CornerRadius="1" 
                                Background="{StaticResource WindowBackgroundBrush}"
                                BorderBrush="{StaticResource SolidBorderBrush}"
                                BorderThickness="1">
                                <ScrollViewer
                                  Focusable="False"
                                  CanContentScroll="False"
                                  Padding="4">
                                    <ItemsPresenter/>
                                </ScrollViewer>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
    
            <!-- TreeViewItem -->
            <Style x:Key="TreeViewItemFocusVisual">
                <Setter Property="Control.Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <Border>
                                <Rectangle Margin="0,0,0,0"
                                   StrokeThickness="5"
                                   Stroke="Black"
                                   StrokeDashArray="1 2"
                                   Opacity="0"/>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <Style x:Key="{x:Type TreeViewItem}" TargetType="{x:Type TreeViewItem}">
                <Setter Property="Background" Value="Transparent"/>
                <Setter Property="HorizontalContentAlignment" Value="{Binding Path=HorizontalContentAlignment,
                        RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
                <Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment,
                        RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
                <Setter Property="Padding" Value="1,0,0,0"/>
                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
                <Setter Property="FocusVisualStyle" Value="{StaticResource TreeViewItemFocusVisual}"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type TreeViewItem}">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition/>
                                </Grid.RowDefinitions>
                                <Border Name="Bd"
                                    Grid.Column="0"
                                    Background="{TemplateBinding Background}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    Padding="{TemplateBinding Padding}">
                                    <ContentPresenter x:Name="PART_Header"
                                        ContentSource="Header"
                                        HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"/>
                                </Border>
                                <ItemsPresenter x:Name="ItemsHost" Visibility="Visible"
                                    Grid.Row="1"
                                    Grid.Column="0"/>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <MultiTrigger>
                                    <MultiTrigger.Conditions>
                                        <Condition Property="HasHeader" Value="false"/>
                                        <Condition Property="Width" Value="Auto"/>
                                    </MultiTrigger.Conditions>
                                    <Setter TargetName="PART_Header" Property="MinWidth" Value="75"/>
                                </MultiTrigger>
                                <MultiTrigger>
                                    <MultiTrigger.Conditions>
                                        <Condition Property="HasHeader" Value="false"/>
                                        <Condition Property="Height" Value="Auto"/>
                                    </MultiTrigger.Conditions>
                                    <Setter TargetName="PART_Header" Property="MinHeight" Value="19"/>
                                </MultiTrigger>
                                <Trigger Property="IsSelected" Value="true">
                                    <Setter TargetName="Bd" Property="Background"
                                        Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
                                    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
                                </Trigger>
                                <MultiTrigger>
                                    <MultiTrigger.Conditions>
                                        <Condition Property="IsSelected" Value="true"/>
                                        <Condition Property="IsSelectionActive" Value="false"/>
                                    </MultiTrigger.Conditions>
                                    <Setter TargetName="Bd" Property="Background"
                                            Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
                                    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
                                </MultiTrigger>
                                <Trigger Property="IsEnabled" Value="false">
                                    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Window.Resources>
    
        <Grid>
            <TreeView>
                <TreeViewItem Header="Node 1">
                    <TreeViewItem Header="Node 1.1">
                        <TreeViewItem Header="Node 1.1.1" />
                    </TreeViewItem>
                </TreeViewItem>
                <TreeViewItem Header="Node 2">
                    <TreeViewItem Header="Node 2.1">
                        <TreeViewItem Header="Node 2.1.1" />
                    </TreeViewItem>
                    <TreeViewItem Header="Node 2.2">
                        <TreeViewItem Header="Node 2.2.1" />
                    </TreeViewItem>
                </TreeViewItem>
            </TreeView>
        </Grid>
    </Window>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone tell me how i can change the .xml file that a flash
Can someone tell me how to change directories using FtpWebRequest? This seems like it
there is insert iterator in database template library or other library, Can someone tell
Can someone tell me the different between LinkButton.PostBackUrl and HyperLink.NavigateUrl? I've got a asp.net
Can someone tell what is wrong with this query? sqltext = SELECT utyp, count(*)
Can someone tell me what the code equivelant in VB.Net to this C# code
Can someone tell me what exactly the two above lines of javascript do? And
Can someone tell me why: var nl = Convert.ToInt64(17029268.1650117); fails, and instead you have
can someone tell me why the following behavior occurs (Oracle 10.2): SQL> create table
Hiya I am working on an FTP client, can someone tell me the difference

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.