0
votes

I want a scroll bar appear in a stack panel when there are too many items to fit in a screen, just like ListBox does. I can't just put it into a scroll viewer, because in that case horizontal StackPanel stops to scale elements verticaly. ScrollViewer tells its content, that it has infinite place to fit in, and items always keep their original size and ScrollViewer just crops elements and shows vertical scrollbar if height is too small or leaves blank space if it is too big. I probably need some tricky override for MeasureOverride() method of a ScrollViewer to make it content fit into that panel without making vertical scrollbar appear and take as much width as it wants, but all my attempts failed so far.

1
Try other panels instead of StackPanel. Grid, Dockpanel, UniformGrid etc.. - Rohit Vats
I never heard of a horizontal StackPanel that scales elements verticaly - dev hedgehog
Please show the code you are working with. It will help in coming up with a solution. - TrueEddie
@dev hedgehog To be honest, i put UserControls there that have Viewbox as a root of a logical tree, they are intended to fill Panel in a counter-orientation direction. - Pavel Masyuk

1 Answers

1
votes

The value of the ScrollViewer.HorizontalScrollBarVisibility and ScrollViewer.VerticalScrollbarVisibility will determine the layout behavior of the elements inside a ScrollViewer.

This:

<ScrollViewer VerticalScrollBarVisibility="Disabled" 
              HorizontalScrollBarVisibility="Auto">
   <StackPanel Orientation="Horizontal">
      <!-- ... -->
   </StackPanel>
</ScrollViewer>

will cause a horizontal scrollbar to appear when needed, while stretching (not scaling, which is something completely different) the StackPanel contents vertically.