I am making a sort of "print preview" control for some documents in my Silverlight 3 application. I have a Canvas (for showing the document) inside of a ScrollViewer, and I have zoom in / zoom out buttons that control the X and Y Scale properties of the ScaleTransform for the Canvas.RenderTransform property. I want the scrollbars of the ScrollViewer to show up when I "zoom in" enough such that the canvas is no longer visible in the ScrollViewer area, but it seems that they only show up depending on the Width/Height of the Canvas itself, regardless of whether it is zoomed in or not.
Can anyone help?
Best Answer
Yeah, the problem is that there is no
LayoutTransform
in Silverlight. There are some workarounds to this problem listed here.The idea here is to provide an intermediate canvas that gets resized and as a result, resizes the scrollable area. For example, if I have the following XAML:
You'll notice that I put the
<Canvas x:Name="sizer"/>
between the<ScrollViewer/>
and<Rectangle/>
and the click event ofScaleRect
in the<Button/>
.The
ScaleRect
sub simply scales the rectangle by 2. That value is then used to change thesizer
Width
andHeight
, thus updating the ScrollViewer's scrollbars. Here's the sub forScaleRect
: