EDIT: I posted in the wrong forum. Could someone move this to the *Silverlight* GridView forum? Thanks
I have a grid with dynamically created columns whose Width
are set to GridViewLength.SizeToCells.
When the databinding is completed, columns resize themselves according to their content.
I'd like to make sure that no column, by default
(ie. on first display), has a width greater than the width of my grid (minus 50 pixels for example). But I don't want to set the MaxWidth: the user must be able to enlarge the column if he or she wishes to.
I tried to change the width in the Grid_LayoutUpdated event, but it's too early: columns don't have their width / desiredwidth / actualwidth calculated yet (at that time, it seems the width is based on the header width only).
Same thing with Grid_Loaded. Too early.
Is there an event on which I can perform this kind of piece of code?
private void Grid_????Event(object sender, System.EventArgs e)
var maxSize = Grid.ActualWidth - 10;
if (maxSize <= 50) // the grid is too small to adjust sizes
// make sure that no column is larger than the grid
foreach (var column in Grid.Columns)
column.Width = Math.Min(maxSize, column.Width.DisplayValue);
Or is there another way to achieve this?