[英]How can I perform RenderTransform within ScrollViewer (WP7)?
我已经尝试了许多方法来在ScrollViewer(Windows Phone 7 Silverlight)中管理RenderTransform,但是在我看来现在几乎是不可能的。 我得到的是在ScrollViewer中具有其大小的Grid,我想通过RenderTransform从代码更改网格的内容大小,因为它什么也不做!
<ScrollViewer x:Name="scrollViewer" Width="800" Height="480" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible">
<Grid x:Name="grid" Width="1600" Height="960" HorizontalAlignment="Left" VerticalAlignment="Top">
<Grid.RenderTransform>
<CompositeTransform x:Name="scaleTransform" ScaleX="1" ScaleY="1"/>
</Grid.RenderTransform>
<Image x:Name="backgroundImage" Source="/Images/backgrounds/Happy rainbow.png" Stretch="Fill"/>
</Grid>
</ScrollViewer>
在代码中:
private void button_Click(object sender, RoutedEventArgs e)
{
(grid.RenderTransform as CompositeTransform ).CenterX = 0;
(grid.RenderTransform as CompositeTransform ).CenterY = 0;
(grid.RenderTransform as CompositeTransform ).ScaleX = 0.5;
(grid.RenderTransform as CompositeTransform ).ScaleY = 0.5;
grid.UpdateLayout();
}
缩放和视觉状态绑定也不会显示。 非常感谢您的帮助。
更好的主意...将网格内容放入ItemsControl,然后在ItemsControl上执行ScaleTransform。
<Grid>
<ItemsControl x:Name="ContentScaler">
<Image x:Name="backgroundImage" Source="/Images/backgrounds/Happy rainbow.png" Stretch="Fill"/>
</ItemsControl>
</Grid>
然后在代码背后
ContentScaler.RenderTransform = new ScaleTransform() { ScaleX = 0.5, ScaleY = 0.5, CenterX = 0, CenterY = 0 };
根据您可能需要执行的其他操作,您可能需要执行诸如将WrapPanel设置为ItemsPanelTemplate和/或在缩放时调整ItemsControl的大小之类的操作。 可能会有些棘手,但是希望这可以使您指向正确的方向。
恕我直言,在Silverlight中使用Grid也会被过度使用,除非需要将内容分解为表格类型的布局。 画布可能更适合您的工作。
我不确定这是否正是您需要的,但是如果您插入这样的额外网格...
<ScrollViewer Grid.Row="1" x:Name="scrollViewer"
Width="800"
Height="480"
HorizontalScrollBarVisibility="Visible"
VerticalScrollBarVisibility="Visible">
<Grid x:Name="grid"
HorizontalAlignment="Left"
VerticalAlignment="Top">
<Grid
Width="1600"
Height="960">
<Grid.RenderTransform>
<CompositeTransform x:Name="scaleTransform"
ScaleX="1"
ScaleY="1" />
</Grid.RenderTransform>
<Image x:Name="backgroundImage"
Source="ApplicationIcon.png"
Stretch="Fill" />
</Grid>
</Grid>
</ScrollViewer>
至少内容会按比例缩放。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.