Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrollable content inside WPF Viewbox with "UniformToFill"

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.

like image 312
rem Avatar asked Mar 22 '11 10:03

rem


1 Answers

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.

like image 181
Laith Avatar answered Nov 20 '22 10:11

Laith