I have learned that if the height of a grid row, where the ScrollViewer
resides, is set as Auto
, the vertical scroll bar will not take effect since the actual size of the ScrollViewer
can be larger than the height in sight. So in order to make the scroll bar work, I should set the height to either a fixed number or star height
However, I now have this requirement, that I have two different views reside in two grid rows, and I have a toggle button to switch between these two views: when one view is shown, the other one is hidden/disappeared. So I have defined two rows, both heights are set as Auto
. And I bind the visibility of the view in each row to a boolean property from my ViewModel (one is converted from True
to Visible
and the other from True
to Collapsed
. The idea is when one view's visibility is Collapsed
, the height of the grid row/view will be changed to 0 automatically.
The view show/hidden is working fine. However, in one view I have a ScrollViewer
, which as I mentioned doesn't work when the row height is set as Auto
. Can anybody tell me how I can fulfill such requirement while still having the ScrollViewer
working automatically`? I guess I can set the height in code-behind. But since I am using MVVM, it would require extra communication/notification. Is there a more straightforward way to do that?