My UI:
<ListView Name="persons" SelectionChanged="persons_SelectionChanged">
<ListView.View>
<GridView AllowsColumnReorder="False">
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}" Width="auto"/>
<GridViewColumn Header="Age" DisplayMemberBinding="{Binding Age}" Width="auto"/>
</GridView>
</ListView.View>
</ListView>
The Codebehind of my UI:
internal void Update(IEnumerable<Person> pers)
{
this.persons.ItemsSource = null;
this.persons.ItemsSource = pers;
UpdateLayout();
}
My Entities:
class Person
{
public string Name { get; set; }
public int Age { get; set; }
}
The GridViewColumns have the width of the GridViewColumn-Header. Even if i call Update() with Persons with a long name. The Column does not get resized.
a) How can i resize the "Name"-column automatically (when i called Update) to the length of the longest Name, but not longer than a Value x (i want to specify a maximum width of a column)?
b) How can i specify that the "Age"-Column fills the space to the control´s end (so that the columns of the gridview uses the complete width of the control)?
I pulled this from How to autosize and right-align GridViewColumn data in WPF?
That help you at all?
GridView does not resize automatically.
To resize the columns you can
As for sizing the last to fill area I do it with a converter. I don't think this converter does exactly what you need for this but it should get you started.
GridView is fast but it takes a bit of baby sitting.