Reputation:
I started maintenance on some poorly written XAMLs. I am relatively new to XAML.
One thing I need is - grid columns should automatically adjust their width per the text contents.
The MSDN documentation on GridViewColumn.Width says - set it to Auto to enable auto-sizing behavior. However even though the code reads as follows, column widths remain the same irrespective of the content text.
<ListView.View>
<GridView>
<GridViewColumn x:Name="lstColName" Width="200">Name</GridViewColumn>
<GridViewColumn x:Name="lstColPath" Width="Auto">Path</GridViewColumn>
</GridView>
</ListView.View>
Upvotes: 3
Views: 7435
Reputation: 14111
The GridView
recalculates column content sizes only when the template or internal column collection change, that's why Width="Auto"
only works on loading the GridView
.
Here's an article about a possible approach to a solution.
Upvotes: 1
Reputation: 3358
Auto does work fine as below.
<ListView>
<ListView.View>
<GridView>
<GridViewColumn x:Name="Spoons" Width="Auto">
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
Upvotes: 0