Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在开发一个 WPF 应用程序。
我有按钮列表(例如)。该列表是在运行时创建的,在设计时我不知道列表中有多少元素(按钮)。我想根据按钮的数量以对称的方式对元素进行排序。
例如:
如果列表包含 4 个按钮,我希望网格有 2 行和 2 列。
如果列表包含 6 个按钮,我希望网格有 2 行和 3 列。
如果列表包含 9 个按钮,我希望网格有 3 行和 3 列。
有没有办法创建这种网格?
我应该使用什么面板?
您可以使用 WPF Grid 容器控件。根据您的要求将 RowDefinitions 和 ColumnDefinitions 添加到 Grid 中。另一种方法是使用带有修复 ItemHeight 和 ItemWidth 的 WrapPanel。