ListView.ItemTemplate 中的 SharedSizeGroup
我有这样的场景,我想在所有 ListViewItems 之间共享列大小,并且我在列定义上使用 SharedSizeGroup 但它不起作用:
<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 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>
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):
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
唯一缺少的是我认为的范围,添加
Grid.IsSharedSizeScope
="True"
到ListView
属性。The only thing that is missing is the scope i think, add
Grid.IsSharedSizeScope
="True"
to theListView
attributes.