代码:
<Grid> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="3*" /> <ColumnDefinition Width="2*" /> <ColumnDefinition Width="2*"/> <ColumnDefinition Width="1*"/> </Grid.ColumnDefinitions> <Grid Grid.Column="0" x:Name="col1"/> <Grid Grid.Column="1" x:Name="col2"/> <Grid Grid.Column="2" x:Name="col3"/> <Grid Grid.Column="3" x:Name="col4"/> </Grid> <ListView x:Name="listview"> <ListView.View> <GridView> <GridViewColumn Header="header1" Width="{Binding ElementName=col1,Path=ActualWidth}"/> <GridViewColumn Header="header2" Width="{Binding ElementName=col2,Path=ActualWidth}"/> <GridViewColumn Header="header3" Width="{Binding ElementName=col3,Path=ActualWidth}"/> <GridViewColumn Header="header4" Width="{Binding ElementName=col4,Path=ActualWidth}"/> </GridView> </ListView.View> </ListView> </Grid>
这种方式有个缺点,如果手动拖动调整标题列列宽,数据列的列宽并不变化。