Silverlightscaletransform调整滚动条
我有以下 UI 元素层次结构:UserControl>ScrollViewer>Canvas。我在画布上画了很多东西,它变得比 UserControl 大,此时 ScrollViewer 显示滚动条。到目前为止,一切都很好。现在,我将 ScaleTransform 应用于画布(例如 2.0,使所有内容变为原来的两倍)。但是,我的滚动条无法调整,所以我现在只能在放大的画布上滚动一半。当我对 ScrollViewer 中显示的画布应用缩放变换时,如何调整 ScrollViewer 滚动条?
I have the following UI element hierarchy: UserControl>ScrollViewer>Canvas. I am drawing lots of stuff on the canvas, and it becomes larger than the UserControl, at which point the ScrollViewer displays the scrollbars. So far, so good. Now I apply a ScaleTransform to the Canvas (say, 2.0, making everything twice as large). However, my scrollbars to not adjust, so I can now only scroll half-way across my enlarged canvas. How do I get my ScrollViewer scrollbars to adjust when I apply a scaletransform to the canvas being displayed within the ScrollViewer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的问题是
ScaleTransform
是RenderTransform
而不是LayoutTransform
。无论比例是多少,它向 ScrollViewer 报告的大小都是相同的。我过去用来解决这个问题的一个解决方案是将画布嵌套在另一个画布中。然后,您可以在代码中更改外部画布的大小以反映内部画布的实际尺寸。然后,
ScrollViewer
将更新以反映正确的尺寸。您实际上并没有改变内部画布的大小,只是改变了比例。Your problem is that the
ScaleTransform
is aRenderTransform
and not aLayoutTransform
. The size it reports to the ScrollViewer is the same size regardless of what the scale is.One solution I've used in the past to get around this is to nest the Canvas in another Canvas. You can then in code change the size of the outer Canvas to reflect the actual dimensions of the inner Canvas. The
ScrollViewer
will then update to reflect the correct dimensions. You don't actually change the size of the inner Canvas, you just change the scale.这个答案应该可以回答你的问题:
XAML:当子对象的 ScaleTransform 变大时,使 ScrollViewer 显示滚动条
This answer should answer your question:
XAML: make a ScrollViewer show scrollbars when the ScaleTransform of a child object gets big