gpt4 book ai didi

c# - 将 WPF 网格更改为原点位于左下角

转载 作者:行者123 更新时间:2023-12-02 01:07:27 25 4
gpt4 key购买 nike

如果我有这样的控件:

<Grid ShowGridLines="True">  
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>

<TextBlock Grid.Column="0" Grid.Row="0" Text="One, One" />
<TextBlock Grid.Column="0" Grid.Row="1" Text="One, Two" />
<TextBlock Grid.Column="0" Grid.Row="2" Text="One, Three" />
<TextBlock Grid.Column="1" Grid.Row="0" Text="Two, One" />
<TextBlock Grid.Column="1" Grid.Row="1" Text="Two, Two" />
<TextBlock Grid.Column="1" Grid.Row="2" Text="Two, Three" />
<TextBlock Grid.Column="2" Grid.Row="0" Text="Three, One" />
<TextBlock Grid.Column="2" Grid.Row="1" Text="Three, Two" />
<TextBlock Grid.Column="2" Grid.Row="2" Text="Three, Three" />
</Grid>

我会得到一个如下所示的网格:

___________________________________________  
| One, One | Two, One | Three, One |
-------------------------------------------
| One, Two | Two, Two | Three, Two |
-------------------------------------------
| One, Three | Two, Three | Three, Three |
-------------------------------------------

有什么我可以做的(除了改变我所有的 Grid.ColumnGrid.Row 设置)让这个网格显示如下:

___________________________________________  
| One, Three | Two, Three | Three, Three |
-------------------------------------------
| One, Two | Two, Two | Three, Two |
-------------------------------------------
| One, One | Two, One | Three, One |
-------------------------------------------

基本上我想将原点从左上角更改为左下角。

(注意:我的真实场景有一个 42 x 30 的网格,许多视觉组件绑定(bind)到网格(按行、列和跨度)。这个问题是我试图避免手动转换绑定(bind)数据。)

最佳答案

您可以通过布局转换来做到这一点。 编辑:将转换简化为单个转换。事实证明,网格的矩阵变换与每个文本 block 的矩阵变换相匹配

这是一个示例屏幕截图:

Example

<Grid ShowGridLines="True">
<Grid.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="LayoutTransform">
<Setter.Value>
<MatrixTransform>
<MatrixTransform.Matrix>
<Matrix M11="1" M12="0" M21="0" M22="-1" />
</MatrixTransform.Matrix>
</MatrixTransform>
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
<Grid.LayoutTransform>
<MatrixTransform>
<MatrixTransform.Matrix>
<Matrix M11="1" M12="0" M21="0" M22="-1" />
</MatrixTransform.Matrix>
</MatrixTransform>
</Grid.LayoutTransform>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>

<TextBlock Grid.Column="0" Grid.Row="0" Text="One, One"/>
<TextBlock Grid.Column="0" Grid.Row="1" Text="One, Two"/>
<TextBlock Grid.Column="0" Grid.Row="2" Text="One, Three"/>
<TextBlock Grid.Column="1" Grid.Row="0" Text="Two, One" />
<TextBlock Grid.Column="1" Grid.Row="1" Text="Two, Two" />
<TextBlock Grid.Column="1" Grid.Row="2" Text="Two, Three" />
<TextBlock Grid.Column="2" Grid.Row="0" Text="Three, One" />
<TextBlock Grid.Column="2" Grid.Row="1" Text="Three, Two" />
<TextBlock Grid.Column="2" Grid.Row="2" Text="Three, Three" />
</Grid>

关于c# - 将 WPF 网格更改为原点位于左下角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20978605/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com