WPF GridView的列宽度设置为按比例分配

<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>  

 

posted @ 2017-07-24 11:13  可乐•雪碧•咖啡•茶  阅读(657)  评论(0编辑  收藏  举报