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); }
Hi again.
I've created and uploaded 2 videos regarding this issue:
Video 1: http://www.fileden.com/files/2007/1/12/633155/Autofit_Resize_Error.avi
The first video depicts the problem that I'm having with Autofit=true. Notice as I resize the columns to the right, the final width is incorrect.
Video 2: http://www.fileden.com/files/2007/1/12/633155/Expected_Behaviour.avi
In the second video, I've relied on LabelPresenters and tapping into the SizeChanged event, and manually modified the widths. Also notice how the columns behave when I resize the entire window (as specified in my requirements). This is the behaviour that I'm after, which Autofit-true wasn't able to provide.
Now, I wouldn't mind sticking with what I have (sizeChanged events, etc). Besides, it seems to work pretty well. However, I am having problems with Vista. What happens is, in Vista, the SizeChanged event gets invoked repeatedly, causing the right column to shrink down to a width of 0; whereas in XP, the sizeChanged event only gets invoked once.
Please help.
Thanks
Hi Josh, and thanks for the reply.
The problem that I was having was, with Autofit=true, when a column is resized, the final width would change once the user lets go of the mouse button. In other words, the user might resize the columns from 50:50 to 80:20, but the final width would be something like 60:40 when he/she releases the mouse.
Perhaps I'm missing another property that needs to be set. But until I can find out what that property is, I'm stuck with adding sizeChanged events to LabelPresenters, and manually modifying the widths of columns.
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?