WPF - 当父级调整大小时自动重新定位子级
我有一个大小可以改变的容器。
我将动态创建用户控件的实例并将它们添加到该容器中。 用户控件的大小是固定的。我想要做的是,在容器中容纳最多数量的用户控件。
我认为一个好的方法是水平添加子项,直到没有更多空间来添加另一个,然后开始另一行。
假设,对于给定宽度的容器,每行可容纳 3 个子级。如果扩展得足够多,它应该会自动容纳 4 个子级成一行。
是否有一个容器控件(StackPanel Grid 等)可以用来托管这些用户控件。需要更改哪些属性。
在调整容器大小时,应该重新定位子项,以便显示最大的子项。只要在任何给定时间显示最大值,滚动就可以。
有没有一个容器可以自动执行此操作?或者我应该手动创建行或面板或其他东西,并向每个添加 n 子项 - 即手动执行?
I have a container whose size can change.
I will by dynamically creating instances of a user control and adding them to that container.
the size of the user control is fixed. what I want to do is, fit the most number of user controls in the container.
I think a good approach is to add the children horizontally until there is no more space to add another and then start another row.
Say, each row fits 3 children for a given width of the container. if it is expanded enough, it should automatically fit 4 children in a row.
Is there a container control (StackPanel Grid etc.) that I can use to host these user controls. What properties need to be changed.
On resizing the container, it should relocate the children so that the maximum children ae shown. Scrolling is okay as long as max are shown at any given time.
Is there a container that does this automatically? or should I manually create rows or panels or something and add n children to each - i.e., do it manually?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您需要的是
WrapPanel< /代码>
。
MSDN 上有面板概述,其中包含更多信息和链接特定类型的
Panel
包括WrapPanel
:I think what you need is a
WrapPanel
.There's a Panels Overview on the MSDN with a lot more information and links to specific types of
Panel
including theWrapPanel
:这正是 WrapPanel 的作用。
This is exactly what a WrapPanel does.