Hi, I need help to produce the following behaviour with XamDatagrid's columns:
First things first, I'm only dealing with 2 columns
So far, I've tried the xaml approach, using Autofit=True and using grids to specify the columns:
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
But the result was a grid where the columns couldn't be resized.
Next I've tried doing it programmatically by listening to the sizechanged event, and trying to update the Field.Settings.Cell(Min|Max)Width property, but the changes were not reflected in grid.
Can anyone give me a simple standalone sample please?
Thanks!
** Here's the code that I'm currently trying to use **
protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) { // Size difference double newSize = sizeInfo.NewSize.Width - sizeInfo.PreviousSize.Width; int columnToEdit = 0; if (newSize<0) { // size shrinking. Hence, shrink the 1st column columnToEdit = 0; } else { // Size expanding. Hence, expand the 2nd column columnToEdit = 1; } // Calculate new width double newWidth = xdgField.DefaultFieldLayout.Fields[columnToEdit].CellWidthResolved + newSize; // Update width values (btw, I've tried different combinations here, eg, w/wo min/max, etc) xdgField.DefaultFieldLayout.Fields[columnToEdit].Settings.CellWidth = newWidth; xdgField.DefaultFieldLayout.Fields[columnToEdit].Settings.CellMinWidth = newWidth; xdgField.DefaultFieldLayout.Fields[columnToEdit].Settings.CellMaxWidth = newWidth; xdgField.DefaultFieldLayout.Fields[columnToEdit].Settings.LabelWidth = newWidth; xdgField.DefaultFieldLayout.Fields[columnToEdit].Settings.LabelMinWidth = newWidth; xdgField.DefaultFieldLayout.Fields[columnToEdit].Settings.LabelMaxWidth = newWidth; base.OnRenderSizeChanged(sizeInfo); }
When I set AutoFit to true on the XamDataGrid, the columns behave how you describe in your list of requirements. What is it about just simply setting AutoFit to true that does not match your needs?