如何更改 UniformGrid 控件的方向?
默认情况下,UniformGrid 显示其子项如下:
1 2 3
4 5 6
7 8 9
我想要如下:
1 4 7
2 5 8
3 6 9
有什么想法吗?
By default, UniformGrid displays it's children as follows:
1 2 3
4 5 6
7 8 9
I want to be as follows:
1 4 7
2 5 8
3 6 9
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最简单的方法就是按照您希望它们显示的顺序插入它们。
如果您在列表框中使用 UniformGrid 作为 ItemsPanel 并通过数据绑定获取项目,请将您正在数据绑定的集合按照您的首选顺序进行排序。
最后,如果您想在视图中执行此操作,此链接描述了两种方法: 在 WPF 中构建列主 UniformGrid
页面不断消失。
就在这里(无图片)< /a> 截至 2017 年 6 月 20 日。
它所做的就是使用布局变换将网格旋转 90 度,然后使用另一个布局变换进一步旋转网格中的每个项目,使它们正面朝上。
Easiest must be to insert them in the order you want them to show up.
If you are using a UniformGrid as an ItemsPanel in a listbox and get the items through databinding, sort the collection you are data binding to your prefered order.
Finally, if you want to do it in the view, this link describes two ways: Building a Column-Major UniformGrid in WPF
The page keeps vanishing.
It's here (sans images) as of 2017-06-20.
What it's doing is rotating the grid 90 degrees with a layout transform, and then further rotating each item in the grid with another layout transform so they're right side up.
解决方案不依赖于损坏的链接:
最后一个答案始终存在损坏的链接,但是...对于偶然发现此页面的任何人,我已经为您编写了一个解决方案。我已将此应用到我的
UniformGrid
中:UniformGrid xaml 示例
这会将整个元素逆时针旋转 90 度,并在其自己的 X 轴上反向显示(对于我们来说,它实际上是 Y 轴,因为它是现在旋转)。通过这样做,网格将按列填充,左上角是第一个要填充的单元格。
不同的方向:
如果您希望以不同的方式工作,您可以随时使用
TransformGroup
值。例如,可以使用Angle="270"
和ScaleX="-1"
实现从右下角开始的列优先。其他两个角是通过使用最后两个角度值并删除 ScaleX 因子或仅将其分配给ScaleX="1"
来实现的。不过还有第二步:
里面的子元素随着网格旋转,所以如果我们希望看到它们“笔直”,我们就必须将它们旋转回去。我们通过给每个元素一个负角度来实现这一点(假设网格角度为
Angle="90"
,我们将使用Angle="-90"
),例如比如:祝你好运!
希望您已经看到了这一点,并且在您绞尽脑汁试图弄清楚为什么 Microsoft 甚至在 .NET 6 中仍然没有实现这一点之前,它对您有所帮助
Solution not dependent on broken links:
Last answer has broken links throughout, but... to anyone that's stumbled upon this page, I've compiled a solution for you. I've applied this to my
UniformGrid
:UniformGrid xaml example
This will rotate the whole element for 90 degrees counter-clockwise and display it invertedly across its own X-axis(it's really Y to our eyes since it's rotated now). By doing this, the grid will be populated column-first, top left being the first cell to be populated.
Different orientations:
If you want this to work differently, you can always play with the
TransformGroup
values. For an example, column-first from the bottom right corner would be achieved withAngle="270"
andScaleX="-1"
. Other two corners are achieved by using last two angle values and deleting the ScaleX factor or just simply assigning it toScaleX="1"
.There's a second step though:
The children inside are rotated with the Grid, so we have to rotated them back, if we hope to see them "straight". We do this by giving each of them a negative angle(let's say the grid angle is
Angle="90"
, we will useAngle="-90"
), like such:Good luck!
Hopefully you've seen this and it helped you before melting your brain trying to figure out why Microsoft still hasn't implemented this even in .NET 6