I have a window that contains a GridView for which one of the columns is set to ‘Auto’. I would like to resize the window to fit once the data has been bound to the ListView and the column’s width has been determined. However, when I check the width of that column (using ActualWidth, at the end of the constructor, after the collection has been assigned), its value is 0.
In one of the other questions I’ve seen related to ASP, there is a GridView with a DataBound event which triggers upon the completion of a data binding. However, for the WPF GridView there are no events, nor are there any events associated with its columns.
Is there an event I can use that will occur after the data has been bound and the width of the column has been calculated? Or is there some other way I can resize the window based on the width of the columns? I want the automatic resizing to occur only once, not every time I change the width of the columns.
I’ve run into situations like this and almost always the answer has been to add an event handler for the
Loadedevent (you register this handler in the constructor) and do your checking for things likeActualWidthin that handler, rather than the constructor. This seems to allow the controls to actually get rendered, so these types of properties then have runtime values set.