默认情况下,UniformGrid将其子元素显示为以下方式:
1 2 3
4 5 6
7 8 9
我想要的是:
1 4 7
2 5 8
3 6 9
有什么想法吗?
1 2 3
4 5 6
7 8 9
我想要的是:
1 4 7
2 5 8
3 6 9
有什么想法吗?
上一个答案中存在损坏链接,但是......对于那些偶然找到此页面的人,我已经为您编写了解决方案。我已将其应用于我的UniformGrid
:
UniformGrid
XAML示例<UniformGrid> <!--Remember to invert the number of rows and columns here-->
<!--content here-->
<UniformGrid.LayoutTransform>
<TransformGroup>
<RotateTransform Angle="90"/>
<ScaleTransform ScaleX="-1"/>
</TransformGroup>
</UniformGrid.LayoutTransform>
</UniformGrid>
这将使整个元素逆时针旋转90度,并沿其自身X轴(现在它已经旋转,对我们来说实际上是Y轴)上下颠倒显示。通过这样做,网格将首先填充列,左上角是要填充的第一个单元格。
如果您希望以不同的方式工作,可以随时调整TransformGroup
值。例如,从右下角开始按列填充将使用Angle="270"
和ScaleX="-1"
实现。使用最后两个角度值并删除ScaleX因子或仅将其分配给ScaleX="1"
即可实现其他两个角落。
内部的子元素与网格一起旋转,因此如果希望看到它们“直”,则必须将它们旋转回来。我们通过为每个子元素赋予负角度(假设网格角度为Angle="90"
,我们将使用Angle="-90"
)来实现这一点。
<Ellipse> <!--I put an ellipse just as an example,
you will apply this to your desired control.-->
<Ellipse.LayoutTransform>
<TransformGroup>
<RotateTransform Angle="90"/>
<ScaleTransform ScaleX="-1"/>
</TransformGroup>
</Ellipse.LayoutTransform>
</Ellipse>
希望你看到这篇文章后,在试图弄明白为什么即使在.NET 6中,微软仍然没有实现这一点之前,它已经帮助了你,避免了大脑短路。