ScrollViewer's ScrollBar Doesn't Appear

RogerSchlueter-7899 1,236 Reputation points

There are two very simple wpf Windows involved in this problem. The first is a UserControl which contains just one TreeView wrapped in a ScrollViewer:


I use this UserControl in three Windows; in two it works just fine but in the third the vertical ScrollBar does not appear. Here is the XAML:

                    FontWeight="SemiBold" />
        <self:Categories />   <---- Here is the UserControl

I've tried numerous ideas but none work. for example, setting


in the UserControl shows a disabled ScrollBar. Setting the SizeToContent property of the containing Window just makes the Window as high as the TreeView no matter which value I set it to. Putting the UserControl inside a Grid on the containing Window makes no difference. Binding the Height or MaxHeight of the ScrollViewer to the ActualHeight of the containing Window makes the TreeView disappear entirely. Neither the suggested answers here or in a wider, independent search have helped. What am I missing?

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,686 questions
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
771 questions
{count} votes

Accepted answer
  1. Hui Liu-MSFT 41,331 Reputation points Microsoft Vendor

    Hi,@Roger Schlueter. If you don't set the height, it won't show the ScrollBar because the height is enough. You set up VerticalScrollBarVisibility = "Auo" in the UserControl. It will display the VerticalScrollBar based on the height of the control. I set the height to 100 in the window and it will display the following.

     <self:Categories Height="100" />

    User's image

    User's image

    When I set VerticalScrollBarVisibility="Visible" in UserControl, the result is shown as follows. <self:Categories />

    User's image

    If the response is helpful, please click "Accept Answer" and upvote it. Note: Please follow the steps in our [documentation][5] to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful