WPF DataGrid列宽 [英] WPF DataGrid Column Width

查看:1476
本文介绍了WPF DataGrid列宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有3列的WPF中的DataGrid。我希望这些列可以占用网格中的所有可用空间。所以例如:



列1占网格宽度的40%
列2占网格宽度的30%
列3占30%的网格宽度



这样,即使调整窗口或网格的大小时,列宽相应调整大小。无论如何我可以实现这一点。



感谢



Regards
Gabriel。

解决方案

我看到你已经根据你的评论找到了你正在寻找的答案。但是,如果有人遇到这个问题,试图找出如何获得列比率(例如列1 = 40%,第2列= 30%,第3列= 30%),您可以指定与*列宽的大小如下:

 < Grid> 
< Grid.ColumnDefinitions>
< ColumnDefinition Width =4 */>
< ColumnDefinition Width =3 */>
< ColumnDefinition Width =3 */>
< /Grid.ColumnDefinitions>
< / Grid>


I have a DataGrid in WPF with 3 columns. I would like these columns to take up all the space available in the grid. So for example:

Column 1 takes 40% of the grid's width Column 2 takes 30% of the grid's width Column 3 takes 30% of the grid's width

Such that even when resizing the window or grid the columns width resizes accordingly. Anyway I can achieve this.

Thanks

Regards Gabriel.

解决方案

I see you already found the answer you were looking for based on your comment. However, in case anybody else runs across this question trying to figure out how to get the column ratios (like your example of Column 1 = 40%, Column 2 = 30%, Column 3 = 30%), you can specify the ratios with * sizing for column widths as follows:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="4*" />
        <ColumnDefinition Width="3*" />
        <ColumnDefinition Width="3*" />
    </Grid.ColumnDefinitions>
</Grid>

这篇关于WPF DataGrid列宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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