tags:

views:

1305

answers:

2

I have recently started maintenance on some poorly written XAMLs. I myself am relatively new to XAML.

One thing I need urgently is - grid columns should automatically adjust their width as 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>

Am I doing something wrong?

A: 

Hi there,

Auto does work fine as below.

    <ListView>
        <ListView.View>
            <GridView>
                <GridViewColumn x:Name="Spoons" Width="Auto">

                </GridViewColumn>

            </GridView>
        </ListView.View>
    </ListView>
Blounty
+1  A: 

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.

kek444