我从这篇文章中学到了如何在缩放ScrollViewer中的元素后显示滚动条: http://www.eightyeightpercentnerd.dreamhosters.com/?p=92
现在,我正在尝试使缩放的对象(在这种情况下是画布)正确地居中于ScrollViewer中。我将通过图片来讲述我的故事(在Screencast.com删除我的文件之前请帮帮我)。
我的XAML:
<ScrollViewer x:Name="ScrollViewer" VerticalAlignment="Top"
VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"
Width="300" Height="300" Margin="0" Padding="0" Background="White">
<Canvas x:Name="DesignSurface" Background="Red">
<Canvas x:Name="Surface" Background="Blue" Height="100" Width="100">
<Canvas.RenderTransform>
<TransformGroup>
<ScaleTransform x:Name="SurfaceScaleTransform" />
</TransformGroup>
</Canvas.RenderTransform>
<!-- ... -->
</Canvas>
</Canvas>
</ScrollViewer>
On initial load, my blue canvas is centered and at 100%:
After decreasing by 50%, the blue canvas is still centered:
After increasing 400% and scrolling to display the top left corner of the blue canvas:
After increasing 400% and scrolling to display the bottom right corner of the blue canvas:
我的问题很简单,如何正确将蓝色画布居中于ScrollViewer或红色画布或其他任何画布中?