SharedSizeGroup in ListView.ItemTemplate

送分小仙女□ 提交于 2019-12-19 05:06:08

问题


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.


回答1:


The only thing that is missing is the scope i think, add Grid.IsSharedSizeScope="True" to the ListView attributes.



来源:https://stackoverflow.com/questions/6416139/sharedsizegroup-in-listview-itemtemplate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!