Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: TreeView or TreeListView Headers Horizontal Scrolling Issue

I downloaded TreeListView from here. It did not showed Horizontal or Vertical Scroll bar when data is clipped. Like this

So I changed its Style to

<Style TargetType="{x:Type l:TreeListView}">
    <Setter Property="ScrollViewer.HorizontalScrollBarVisibility"
            Value="Auto" />
    <Setter Property="ScrollViewer.VerticalScrollBarVisibility"
            Value="Auto" />
    <Setter Property="VerticalContentAlignment"
            Value="Center" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type l:TreeListView}">
                <Border BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}">
                    <DockPanel>
                        <GridViewHeaderRowPresenter Columns="{StaticResource gvcc}"
                                                    DockPanel.Dock="Top" />
                        <ScrollViewer x:Name="_tv_scrollviewer_"
                                      Background="{TemplateBinding Background}"
                                      CanContentScroll="False"
                                      Focusable="True"
                                      HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
                                      Padding="{TemplateBinding Padding}"
                                      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                      VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}">
                            <ItemsPresenter />
                        </ScrollViewer>
                    </DockPanel>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="VirtualizingStackPanel.IsVirtualizing"
                             Value="true">
                        <Setter Property="CanContentScroll"
                                TargetName="_tv_scrollviewer_"
                                Value="true" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Vertical Scrollbar is fine. But the problem is Horizontal Scollbar. When data gets clipped horizontally, and scrollbar is moved on right, the data moves right but headers stay where they are. Like this.

How to overcome this problem that when treeitem is scrolled horizontally, headers move with it. I am not allowed to put headers in scrollviewer because they need to be visible when data is scrolled vertically.

like image 701
Nikhil Agrawal Avatar asked Nov 13 '22 06:11

Nikhil Agrawal


1 Answers

If you want the complete treeview (including the header) to scroll horizontally, additionanly add a scrolviewer like this:

<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled" >
    <Treeview/>
</ScrollViewer>
like image 60
Marc Van Camp Avatar answered Nov 14 '22 23:11

Marc Van Camp