是的,问题是LayoutTransform
Silverlight 中没有。这里列出了一些解决此问题的方法。
这里的想法是提供一个中间画布,它可以调整大小,从而调整可滚动区域的大小。例如,如果我有以下 XAML:
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="200" />
<RowDefinition Height="25" />
</Grid.RowDefinitions>
<ScrollViewer Grid.Row="0" x:Name="sc" VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto" Width="200" Height="200" >
<Canvas x:Name="sizer" Width="200" Height="200">
<Rectangle x:Name="gradientRect" Width="200" Height="200">
<Rectangle.RenderTransform>
<ScaleTransform ScaleX="1" ScaleY="1"/>
</Rectangle.RenderTransform>
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
<GradientStop Color="Red" Offset="0.1"/>
<GradientStop Color="Yellow" Offset="0.5"/>
<GradientStop Color="Red" Offset="0.9"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
</Canvas>
</ScrollViewer>
<Button Grid.Row="1" Content="Multiply by Two" Click="ScaleRect" Width="100" Height="25"></Button>
</Grid>
你会注意到我把<Canvas x:Name="sizer"/>
and<ScrollViewer/>
和<Rectangle/>
click 事件ScaleRect
放在了<Button/>
.
sub 只是将ScaleRect
矩形缩放 2。然后使用该值更改sizer
Width
and Height
,从而更新 ScrollViewer 的滚动条。这是子ScaleRect
:
Private Sub ScaleRect(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim zoom As Double = 2.0
Dim scaleX = gradientRect.RenderTransform.GetValue(ScaleTransform.ScaleXProperty)
Dim scaleY = gradientRect.RenderTransform.GetValue(ScaleTransform.ScaleYProperty)
gradientRect.RenderTransform.SetValue(ScaleTransform.ScaleXProperty, scaleX * zoom)
gradientRect.RenderTransform.SetValue(ScaleTransform.ScaleYProperty, scaleY * zoom)
sizer.Height *= zoom
sizer.Width *= zoom
End Sub