如何获取 ListView GridViewColumn 来填充网格中的剩余空间? [英] How can I get a ListView GridViewColumn to fill the remaining space in my grid?
问题描述
我想创建一个 ListView,它有两列固定宽度,第三列填充剩余空间.所以是这样的:
I want to create a ListView that has two columns with a fixed width and a third column to fill in the remaining space. So something like this:
<ListView>
<ListView.View>
<GridView>
<GridViewColumn Header="Name" Width="*" />
<GridViewColumn Header="Age" Width="50" />
<GridViewColumn Header="Gender" Width="50" />
</GridView>
</ListView.View>
</ListView>
问题是我找不到让 Name
列填充剩余空间的方法,因为将宽度设置为 *
不起作用.看起来有一种方法可以使用 值转换器,但似乎应该有一个更简单的方法.与 DataGrid 控件一样,您可以使用 *
s 指定列的宽度.
The problem is I can't find a way to get the Name
column to fill in the remaining space, as setting the width to *
doesn't work. It looks like there is a way to do this with a value converter, but it seems like there should be a simpler way. Like with a DataGrid control, you can specify the widths of columns with *
s.
推荐答案
问题是 GridViewColumn 的列宽是两倍,而不是 GridLength 对象,并且没有适当的转换来处理 *.不确定这是否是 WPF 团队的疏忽.你会认为它应该得到支持.
The issue is the column width of a GridViewColumn is double, rather than a GridLength object, and there is no conversion in place to handle the *. Not sure if this is an oversight by the WPF team or not. You would think it should be supported.
除了转换器,我见过的唯一其他方法是:http://www.ontheblog.net/CMS/Default.aspx?tabid=36&EntryID=37.
Aside from the converter, the only other way I've seen it done is here: http://www.ontheblog.net/CMS/Default.aspx?tabid=36&EntryID=37.
两者都是不需要的额外工作.我在 ListView 和 GridView 组合中发现了其他奇怪"的东西,所以我不再使用它们.如果我需要一个数据网格,我使用我们许可的第 3 方,如果我需要一个复杂的 ListBox 样式菜单,我只使用模板化的 ListBox.
Both are additional work that should not be required. I have found other "weird" things with the ListView and GridView combo so I quit using them. If I need a datagrid I use the 3rd party one we license, if I need a complex ListBox style menu, I just use a templated ListBox.
这篇关于如何获取 ListView GridViewColumn 来填充网格中的剩余空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!