ListView.GridViewColumn (*) 宽度 [英] ListView.GridViewColumn (*) width

查看:16
本文介绍了ListView.GridViewColumn (*) 宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 WPF 应用程序中使用 ListView 控件而不是 DataGrid.我想为我的 ListView.GridViewColumn 提供 * 宽度,但是每当我为 ListView.GridViewColumn 提供 * 宽度时>,它给了我一个编译时错误.请建议我如何为 ListView.GridViewColumn 提供 * 宽度,以便在最大化屏幕时 ListView.GridViewColumn 可以自动填充额外空间.

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

推荐答案

请尝试该解决方案:

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

这篇关于ListView.GridViewColumn (*) 宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆