7

How could I make the content which is put inside WPF Viewbox with Stretch="UniformToFill" be scrollable?

For example:

<Grid Height="500" Width="1000" >
  <ScrollViewer VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Visible" >
      <Viewbox Stretch="UniformToFill">
       ......

      </Viewbox>
   </ScrollViewer>
</Grid>

The content is resized to fill the destination dimensions while it preserves its native aspect ratio. If the aspect ratio of the destination differs from the source, the source content is clipped to fit in the destination dimensions.
So I tried to use ScrollViewer to be able to scroll to the areas of the source content which were clipped, but the Scrollbars are visible but disabled.

I tried ClipToBounds="False" but it didn't help.

rem
  • 16,745
  • 37
  • 112
  • 180
  • it's pretty unusual to put a viewbox in a scrollviewer. one resizes the content to fit in a certain amount of space, the other lets the user scroll around to view content that is too big for the space. maybe you should step back and describe what you are trying to achieve? – Robert Levy Mar 22 '11 at 13:29
  • 1
    @Robert Levy Viewbox content consists of an unpredictable number of other controls. The Viewbox is needed for scaling the content up and down and the ScrollViewer for reaching that content when it's scaled up. – rem Mar 22 '11 at 13:47

1 Answers1

17

The ViewBox resizes its content based on the dimensions it occupies. The ScrollViewer gives its content infinite width/height to render. So, when you put a ViewBox inside a ScrollViewer, the ViewBox thinks it has "all the space in the world" to stretch.

Also, the ViewBox uses render transformations to stretch the content, which means your ScrollViewer will never know the final size of the content.

To make your ScrollViewer work, you have to put a Width/Height on the ViewBox. It needs to know how much space it's occupying.

Laith
  • 6,071
  • 1
  • 33
  • 60