WPF:树视图或TreeListView头水平滚动发行 [英] WPF: TreeView or TreeListView Headers Horizontal Scrolling Issue

查看:1677
本文介绍了WPF:树视图或TreeListView头水平滚动发行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下载TreeListView从这里。当数据被裁剪它并没有表现出水平或垂直滚动​​条。像这样

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>



垂直滚动条的罚款。但问题是水平Scollbar。当数据被修剪水平和滚动条移动在右边,数据向右移动,但头部留他们在哪里。像这样的。

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.

如何克服这种问题,即当treeitem水平滚动,标头一起移动。我不能把标题中的ScrollViewer因为他们需要数据时垂直滚动可见。

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.

推荐答案

我有同样的问题用这种树的,现在是由sincronizing滚动条解决。我添加了一个滚动条是horizo​​ntaly和残疾人hidded垂直的GridViewHeaderRowPresenter,我用从CodeProject一个代码,已经实现滚动条sincronization。

I had the same issue with this kind of tree and now is solved by sincronizing scrollbars. I added a scroll bar to the GridViewHeaderRowPresenter that is hidded horizontaly and disabled vertically, and I used a code from codeproject that already implements sincronization of scrollbars.

<DockPanel>
        <ScrollViewer DockPanel.Dock="Top" HorizontalScrollBarVisibility="Hidden"
                    VerticalScrollBarVisibility ="Disabled"
                    controls:ScrollSynchronizer.ScrollGroup="Group1">
          <GridViewHeaderRowPresenter Columns="{StaticResource gvcc}"/>
         </ScrollViewer>
         <ScrollViewer  
                     HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
                     VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
                     controls:ScrollSynchronizer.ScrollGroup="Group1">
                  <ItemsPresenter />
          </ScrollViewer>
</DockPanel>



链接到库中的 http://www.codeproject.com/Tips/564665/Synchronize-Two-Scroll-Viewers-in-WPF
和用于LIB http://www.codeproject.com/Articles / 39244 /滚动同步。

这篇关于WPF:树视图或TreeListView头水平滚动发行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆