I've seen a lot of posts here on the issue of resizing the width of the columns at runtime but did't find the answer I'm looking for.
I have the following request:
When the user double-clicks the label of the column , th column shoul resize to let's say 300, and this is the code I'm using to acheive this:
{
labelPresenter.Field.Settings.LabelWidth = 300;
labelPresenter.Field.Settings.CellWidth = 300;
e.Handled =
true;
}
Simple, but it doesn't work as expected. The behaviour I'm seeing is as follows:
1. Uer double-clicks the 1st time --> the column is resized to 300
2. User drags the field separator and resizes the width of the column to let's say 50
3. User coubld-clicks again --> expected result : the column is resized back to 300 , but nothing happens. The column is not resized to 300.
After a short investigation, in debugger I saw that what the user resizes the field only the CellWidthResolved and LabelWidthResolved properties of the Field change, but the CellWidth and the LabelWith properties of FieldSettings stay the same.
Is it a bug? Am I doing something wrong here? I thought it would be easy, straight forward.
I have v9.1 version installed
Pls, help.
Hello,
When you resize the Field the first time, the XamDataGrid saves it as customization.
In order for this to be working as you expect, you have to clear this particular customization. Please try with the following extra line of code:
private void onHeaderDoubleClick(object sender, RoutedEventArgs e)
xamDataGrid1.ClearCustomizations(CustomizationType.FieldExtent);
LabelPresenter labelPresenter = (sender as LabelPresenter);
e.Handled=true;
Hope this helps.
Alex,
one more problem: xamDataGrid1.ClearCustomizations(CustomizationType.FieldExtent); clears the customization for all fields, but I want to resize this way only one field, the one that was clicked.
Unfortunately, this is a drawback, because changing the width or position in procedural code and by user action interferes with Saving the customizations logic.
You can submit a feature request here so that there will be an option for this.