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>
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.
Best Answer
I was trying to achieve the same thing but then decided I would like my ListView columns to consume a percentage of the ListView instead, the result of this is all columns consuming a portion of space and all space being consumed in the ListView. You could set this up to have whatever percentage you like on the last column to directly achieve your 'fill remaining space on last column' goal.
I find this method fairly robust and reliable (even on resize!) so thought I might share.
I have four columns in my ListView for this example. All you need is to register the
SizeChanged
event in your ListView with the below event handler: