Scrolling content inside WPF Viewbox with "UniformToFill"

How can I make the content placed inside a WPF Viewbox with Stretch="UniformToFill" scrollable ?

For example:

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

The content is modified to fill in the target dimensions, while maintaining its own aspect ratio. If the aspect ratio of the destination is different from the source, the original content is cropped to fit the size of the destination.
So I tried using ScrollViewer to scroll to areas of the original content that were cropped, but the scroll bars are visible but disabled.

I tried ClipToBounds="False" , but that did not help.

+7
source share
1 answer

ViewBox resizes content based on the size it takes. ScrollViewer provides its infinite width / height content for rendering. So, when you put the ViewBox inside the ScrollViewer, the ViewBox thinks it is "all the space in the world" is stretched.

In addition, the ViewBox uses visualization transforms to stretch the content, which means that ScrollViewer will never know the final size of the content.

To make ScrollViewer work, you have to put the width / height in the ViewBox. He must know how much space he takes.

+15
source

All Articles