开发者

How to have a vertical scrollbar for a WPF TreeView, but not the horizontal scrollbar?

开发者 https://www.devze.com 2023-02-27 05:02 出处:网络
I have a TreeView (the only co开发者_如何学JAVAntrol) inside a Grid, and I only want to see the vertical scrollbar when the height isn\'t enough.

I have a TreeView (the only co开发者_如何学JAVAntrol) inside a Grid, and I only want to see the vertical scrollbar when the height isn't enough.

To not have the horizontal scrollbar, I have to account for its width to the width of the TreeView, right? But when I only specify the width to stretch the TreeView's width to the width of the Window, no scrollbar appears.

Is there a way to solve this?

Alternatively if I can make it so that I don't have to specify the width and height of the TreeView and it resizes its width when the height isn't enough, to fit the vertical scrollbar, that would be the best.


I use these attributes on my TreeView's ScrollViewer:

<TreeView ScrollViewer.VerticalScrollBarVisibility="Auto"
          ScrollViewer.HorizontalScrollBarVisibility="Disabled" />

As long as the width of your TreeView's content stretches to just fit the width of your TreeView, you should be fine.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号