views:

63

answers:

2

I have the following UI element hierarchy: UserControl>ScrollViewer>Canvas. I am drawing lots of stuff on the canvas, and it becomes larger than the UserControl, at which point the ScrollViewer displays the scrollbars. So far, so good. Now I apply a ScaleTransform to the Canvas (say, 2.0, making everything twice as large). However, my scrollbars to not adjust, so I can now only scroll half-way across my enlarged canvas. How do I get my ScrollViewer scrollbars to adjust when I apply a scaletransform to the canvas being displayed within the ScrollViewer?

+2  A: 

Your problem is that the ScaleTransform is a RenderTransform and not a LayoutTransform. The size it reports to the ScrollViewer is the same size regardless of what the scale is.

One solution I've used in the past to get around this is to nest the Canvas in another Canvas. You can then in code change the size of the outer Canvas to reflect the actual dimensions of the inner Canvas. The ScrollViewer will then update to reflect the correct dimensions. You don't actually change the size of the inner Canvas, you just change the scale.

Stephan