ListView.ItemTemplate 中的 SharedSizeGroup [英] SharedSizeGroup in ListView.ItemTemplate
问题描述
我有这种情况,我想在所有 ListViewItems 之间共享列大小,并且我在列定义上使用 SharedSizeGroup 但它不起作用:
I have this scenario where I want to share the column size among all the ListViewItems, and I'm using SharedSizeGroup on the column definitions but it doesn't work:
<ListView ItemsSource="{Binding}">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="A" />
<ColumnDefinition Width="Auto" SharedSizeGroup="B" />
<ColumnDefinition Width="Auto" SharedSizeGroup="C" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Margin="10,0" Text="{Binding Text1}" />
<TextBlock Grid.Column="1" Margin="10,0" Text="{Binding Text2}" />
<TextBlock Grid.Column="2" Margin="10,0" Text="{Binding Text3}" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
我知道一个可能的解决方案是使用 GridView 作为 ListView.View,但是有一些设计问题阻止我们这样做.有没有其他方法可以实现共享列宽?
I know a possible solution is using a GridView as the ListView.View, but there's a few design issues that prevent us from doing this. Is there any other way I can achieve sharing the column widths?
这就是我想要实现的(相同颜色的列应该共享宽度):
This is what I want to achieve (the columns with the same colors should share width):
提前致谢.
推荐答案
唯一缺少的是我认为的范围,添加 Grid.IsSharedSizeScope
="True"
到 ListView
属性.
The only thing that is missing is the scope i think, add Grid.IsSharedSizeScope
="True"
to the ListView
attributes.
这篇关于ListView.ItemTemplate 中的 SharedSizeGroup的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!