Silverlight 画布滚动条

发布于 2024-09-11 10:18:39 字数 332 浏览 7 评论 0原文

我读过,将画布放置在滚动查看器中是行不通的,因为画布不会报告其大小。我一直在尝试不同的容器(边框、网格、画布和滚动查看器),并且确实可以简单地解释滚动查看器在嵌套容器中的行为方式。例如,如果我有一个 UserControl>Grid1>Canvas1>ScrollViewer>Grid2>Canvas2 的容器层次结构,当 Canvas2 变得比 Canvas1 宽时,滚动条是否应该出现在 Grid2 周围? (或者实际上比 UserControl 更宽)如果不是,我应该如何组织我的容器,以便我可以向 Canvas2 添加大量 uielements 并根据需要显示滚动条。 (我的用户控件宽度和高度设置为100%)

I have read that placing a canvas inside a scrollviewer won't work because the canvas does not report its size. I have been experimenting with different containers (borders, grids, canvases and scrollviewers) and could really do with a simple explanation of how scrollviewers behave within nested containers. e.g. If I have a container hierarchy of UserControl>Grid1>Canvas1>ScrollViewer>Grid2>Canvas2 should scrollbars appear around Grid2 when Canvas2 becomes wider than Canvas1? (or indeed wider than UserControl) If not, how should I organise my containers so I can add loads of uielements to Canvas2 and have scrollbars appear as necessary. (My usercontrol width and height are set to 100%)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋千易 2024-09-18 10:18:39

如果您明确指定尺寸,Canvas 将与 ScrollViewer 一起使用。问题来自这样一个事实:如果您不为任何控件提供高度和宽度,它将尝试根据其父容器确定其可用区域。然而,ScrollViewer 具有无限的可用区域。

网格为例。如果我定义一个具有 2 个星形宽度列和 2 个星形高度行的 Grid。 Grid 如何知道每一列的宽度应该是多少?星星表示它们应该是可用区域的一半,但在 ScrollViewer 内,可用区域是无穷大。

您要向 Canvas2 添加哪些控件?如果您以固定位置添加它们,则 ScrollViewer 将展开以容纳所有元素。如果您没有给它们固定的位置,那么所有控件都会堆叠在一起,因为这是 Canvas 的排列行为

Canvas will work with a ScrollViewer if you explicitly give it a size. The problem comes from the fact that if you don't supply a Height and Width for any control it will try and determine it's available area based off it's parent container. A ScrollViewer however has infinite available area.

Take a Grid for example. If I define a Grid that has 2 Star Width columns and 2 Star Height rows. How does the Grid know how wide each of those columns should be? The star says they should be half of the available area, but inside a ScrollViewer the available area is infinity.

What controls are you adding to Canvas2? If you are adding them with fixed positions than the ScrollViewer will expand to house all elements. If you aren't giving them fixed positions than all the controls will stack on top of each other, because that is the arrange behavior of a Canvas

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文