I am storing column widths on application exit and restore them on startup. Everything works fine unless user double click header. This would cause column width become double.NaN
which I understood is a flag for autosizing. Then I have problems.
While investigating the issue I noticed what setting column width to NaN
will enable auto-resizing but only for one time.
Here is a repro:
<ListView x:Name="listView">
<ListView.View>
<GridView>
<GridViewColumn Header="A" Width="NaN" />
</GridView>
</ListView.View>
</ListView>
Then add two buttons with following click handlers:
void button1_Click(object sender, RoutedEventArgs e) => listView.Items.Add("abcd");
void button2_Click(object sender, RoutedEventArgs e) => listView.Items.Add("ABCDEFGHIJKL");
Clicking button1
first will autosize column to fit "abcd"
. Clicking then button2
won't.
Why? Is there a workaround to have it either always autosizing or to at least disable user double-click resizing (tried this solution without success)?