Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why XAML Width="Auto" does not work for me?

Tags:

xaml

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>

1 Answers

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.

like image 163
Kenan E. K. Avatar answered Feb 17 '26 00:02

Kenan E. K.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!