This question is locked. New answers and comments are not allowed.
Hi,
I am having a few issues with column widths.I have three columns, one and two are SizeMode="Auto" and column three is SizeMode="Stretch".
Issue 1:
When the grid is resized, Column 3 does not resize to fill the available space. I have worked around this by changing the SizeMode of Column 3 to "Fixed" and putting in a SizeChanged event handler like this:
Is there a better way?
Issue 2:
If I change the content of Column 1 or 2 so that the Column becomes wider, how do I respond to that event so that I can recalculate the width of Column 3?
Issue 3:
If I change the content of Column 1 or 2 so that the content is narrower, the Column width does not shrink and instead there is blank space. How do I fix this? The columns can grow, but they never shrink.
Thanks,
Dunc
I am having a few issues with column widths.I have three columns, one and two are SizeMode="Auto" and column three is SizeMode="Stretch".
Issue 1:
When the grid is resized, Column 3 does not resize to fill the available space. I have worked around this by changing the SizeMode of Column 3 to "Fixed" and putting in a SizeChanged event handler like this:
private void DataGrid_OnSizeChanged(object sender, SizeChangedEventArgs e){ const int magicNumber = 30; var newWidth = e.NewSize.Width - DataGrid.Columns[0].ActualWidth - DataGrid.Columns[1].ActualWidth - magicNumber; newWidth = Math.Max(200, newWidth); DataGrid.Columns[2].Width = newWidth;}Is there a better way?
Issue 2:
If I change the content of Column 1 or 2 so that the Column becomes wider, how do I respond to that event so that I can recalculate the width of Column 3?
Issue 3:
If I change the content of Column 1 or 2 so that the content is narrower, the Column width does not shrink and instead there is blank space. How do I fix this? The columns can grow, but they never shrink.
Thanks,
Dunc