WPF: TreeView or TreeListView Headers Horizontal Scrolling Issue

丶灬走出姿态 提交于 2019-12-05 19:29:32
Alina

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>

Link to the library http://www.codeproject.com/Tips/564665/Synchronize-Two-Scroll-Viewers-in-WPF and the original article for the lib http://www.codeproject.com/Articles/39244/Scroll-Synchronization.

Marc Van Camp

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>

I believe setting HorizontalScrollBarVisibility="Disabled" should force the contents of the scrollviewer inside. With the scrollbar disabled, it should keep it from messing up the render. This has actually been a problem for a couple of versions. I am unsure if it has been fixed in the latest WPF.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!