如何在视图框内显示矩形画布的一半
我有一个 Canvas 元素,其宽度为 1400 像素,高度为 750 像素。此画布包含 2 个路径元素,它们沿垂直轴对称且并排放置。
该 Canvas 位于 ViewBox 内部,因为用户可以调整拥有 Canvas 的 ContentControl 的大小,并且我希望缩放 Canvas。
现在,我在 ViewBox 中看到了两条路径。
我想做的是,仅在 ViewBox 中显示画布的左半部分(这半部分已正确调整大小),并且能够使用画布的平移来显示画布的右半部分故事板和属性触发器。
我认为我可以应付动画部分,但现在我在显示方面遇到了困难。
您将如何编写 XAML 以获得我想要的内容?
预先感谢
迈克尔
I have a Canvas element, which has a width of 1400 pixels and a height of 750 pixels. This Canvas contains 2 Path elements, which are symmetrical, along a vertical axis, and which are positioned side by side.
This Canvas is inside a ViewBox, because the user can resize the ContentControl owning the Canvas, and I want the Canvas to be scaled.
For now, I see both Paths in the ViewBox.
What I would like to do, is to only display the left half of the canvas in the ViewBox (with this half being correctly resized), and to be able to display the right half of the canvas with a translation of the canvas, using a storyboard and a property trigger.
I think I can cope with the animation part, but now I'm struggling with the display.
How would you write the XAML to have what I'd like?
Thanks in advance
Michael
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚找到了如何做到这一点:
我需要将 Canvas 放入网格中,并将属性 ClipToBounds 设置为 true 并将 Width 设置为 700(画布宽度的一半),然后将该网格放入视图框中。
这是完整的 XAML 代码,还有动画部分:
我希望这会对某人有所帮助:)
I've just found how to do that:
I needed to put the Canvas in a grid with properties ClipToBounds set to true and Width to 700 (half of the width of the canvas), and put that grid in the viewbox.
Here is the complete XAML code, with the animation part too:
I hope this will help someone :)