如何对齐通过模板沿其列/行创建的单独网格? [英] How to align separate Grids created via templates along their columns / rows?
本文介绍了如何对齐通过模板沿其列/行创建的单独网格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我认为在这种情况下,一张图片值一千字:
I thinks that in this case A picture is worth a thousand words:
XAML:
<Grid>
<ItemsControl ItemsSource="{Binding Persons}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Name}" Background="LightBlue"/>
<TextBlock Text="{Binding Age}" Background="LightPink" Grid.Column="1"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
p.s-我不想为第一列设置特定的,而是给它提供所需的最大值.
p.s - I don't want to set a specific with to the first column, but to give it the max with that it needs.
更新: 我已经尝试了ColinE的链接并完成了此操作:
Update: I've tried ColinE's link and done this:
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="A" Width="Auto"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
但这对我没有用.
推荐答案
您需要为每个列使用一个SharedSizeGroup.
You need to use a SharedSizeGroup for each column.
查看本教程...
http://blogs.interknowlogy.com/johnbowen/存档/2007/08/27/21132.aspx
此外,请确保网格的共享大小范围属性为true:
Also, ensure that the shared size scope property is true for your grid:
<Grid Grid.IsSharedSizeScope="True">
<ItemsControl ItemsSource="{Binding Persons}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="A"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Name}" Background="LightBlue"/>
<TextBlock Text="{Binding Age}" Background="LightPink" Grid.Column="1"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
这篇关于如何对齐通过模板沿其列/行创建的单独网格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文