Silverlight ScrollViewer 缩放后未更新
我有一个 Silverlight 网格,其中包含一堆内容(矩形、文本块等),它们代表房间中的内容。因为它变得相当复杂,所以我决定需要一种“放大”网格的能力。我找到了一些很好的代码来做到这一点,但问题是在缩放网格后,关联的 ScrollViewer 不会向下或向右滚动整个距离。我怎样才能强制它更新,以便我可以滚动到底部并一直滚动到右侧?
如果有帮助,这里是允许缩放网格的代码:
var style = new Style(typeof(Grid));
var scale = new ScaleTransform();
scale.CenterX = .5;
scale.CenterY =.5;
scale.ScaleX = Scale;
scale.ScaleY = Scale;
var rs = new Setter();
rs.Property = DataGridCell.RenderTransformProperty;
rs.Value = scale;
style.Setters.Add(rs);
OtdrPatchLocationGrid.Style = style;
这是显示网格和滚动查看器的 XAML
<ScrollViewer Name="scViewer" Grid.Row="1" Visibility="Visible" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Visible">
<Grid x:Name="OtdrPatchLocationGrid" MinHeight="350" VerticalAlignment="Stretch" Background="Yellow" Grid.Row="1" Grid.Column="0" Margin="0" MouseDown="OtdrRackViewer_MouseDown">
</Grid>
</ScrollViewer>
I have a Silverlight grid with a bunch of content in it (rectangles, textBlocks, etc.) which represents content in a room. Because it gets pretty complex, I decided I needed an ability to "zoom-in" on the grid. I found some good code to do that, but the problem is that after zooming the grids associated ScrollViewer doesn't scroll the full distance down or to the right. How can I force it to update so that I can scroll to the bottom and all the way to the right?
If it helps, here's the code to permit zooming of my Grid:
var style = new Style(typeof(Grid));
var scale = new ScaleTransform();
scale.CenterX = .5;
scale.CenterY =.5;
scale.ScaleX = Scale;
scale.ScaleY = Scale;
var rs = new Setter();
rs.Property = DataGridCell.RenderTransformProperty;
rs.Value = scale;
style.Setters.Add(rs);
OtdrPatchLocationGrid.Style = style;
and here is the XAML that shows the grid and the scroll viewer
<ScrollViewer Name="scViewer" Grid.Row="1" Visibility="Visible" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Visible">
<Grid x:Name="OtdrPatchLocationGrid" MinHeight="350" VerticalAlignment="Stretch" Background="Yellow" Grid.Row="1" Grid.Column="0" Margin="0" MouseDown="OtdrRackViewer_MouseDown">
</Grid>
</ScrollViewer>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我现在正在研究同样的问题,
ScrollViewer 仅受宽度或高度变化的影响,
因此,要解决该问题,您必须执行以下操作:
获得了名为(ZoomCanvas)的网格或画布:
假设我们在后面的代码中
I'm working on the same issue now,
the ScrollViewer is affected only by the change in Width or Height,
so to fix the problem, you have to do as the following:
suppose we got the Grid or Canvas named (ZoomCanvas)
in the code behind: