Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
889 views
in Technique[技术] by (71.8m points)

wpf - ListView.GridViewColumn (*) width

I am using ListView control instead of DataGrid in my WPF application. I want to give * width to my ListView.GridViewColumn, but whenever I am providing * width to ListView.GridViewColumn, it gives me a compile time error. Kindly suggest me how can I provide * width to ListView.GridViewColumn, so that ListView.GridViewColumn can automatically fill extra space when I maximize screen.

Any help on this will highly appreciated. Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Please try that solution:

<ListView>
    <ListView.View>
        <GridView>
            <GridViewColumn Header="column1" x:Name="col1"/>
            <!--Column that shall resize: Width is set to the Actual Width of the helper field defined below-->
            <GridViewColumn Header="column2" 
                            Width="{Binding ElementName=helperField, Path=ActualWidth}"/>
        </GridView>
    </ListView.View>
    Test Text
</ListView>

<!--This is the hidden helper Grid which does the resizing -->
<Grid Visibility="Hidden">
    <Grid.ColumnDefinitions>
        <!--Width is bound to width of the first GridViewColumn -->
        <ColumnDefinition Width="{Binding ElementName=col1, Path=ActualWidth}"/>
        <!--Width is set to "Fill"-->
        <ColumnDefinition Width="*"/>
        <!--Correction Width-->
        <ColumnDefinition Width="10"/>
    </Grid.ColumnDefinitions>
    <!--This is the hidden helper Field which is used to bind to, using the "Fill" column of the helper grid-->
    <Grid Grid.Column="1" x:Name="helperField"/>
</Grid>

You could also find some other solution at the following link:

http://social.msdn.microsoft.com/forums/en-US/wpf/thread/3ee5696c-4f26-4e30-8891-0e2f95d69623/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...