I'm running into issues with column widths in two different areas using the 11.1 release. I have a grid where all columns have Width="*" in their XAML.
First, when we try to export the grid to Excel, all columns are very small. See below:
I also have a customized GroupByRecordPresenter. A grid column is bound to the width of the first xamdatagrid column. Here's the xaml:
<Grid.ColumnDefinitions> <ColumnDefinition Width="{Binding ElementName=grdOrder, Path=DefaultFieldLayout.Fields[0].CellWidthResolved}"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <TextBlock Background="White" Foreground="Black" Text="{Binding Path=Record.ChildRecords, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ATMTextConverter}, ConverterParameter=Instrument}" Margin="0,0,1,0" Grid.Column="0"/>
The result of this binding is below:
You can see some text on the left cut off.
For both the Excel export and the grouping customization, manually changing the column width fixes the layout problems. For example:
In both cases, I just want the column widths to just work when the xamdatagrid column width is set to star. I have been unable to get a usable value from CellWidthResolved or LabelWidthResolved properties.
Hell Dierk,
I have been looking into your first issue and I could not be able to reproduce it on my side. I am attaching a sample application(XamDataGridExportToExcel.zip) that I have used for my tests.
Could you please modify it in order to meet exactly your scenario ?
Looking forward to hearing from you.
Hi Dierk,
I believe the reason for this behavior is that your DataGrid has too many columns.
May be you can add some additional logic to the export process. For example you can hook up to the HeaderAreaExporting event...
DataPresenterExcelExporter exporter = new DataPresenterExcelExporter();
exporter.HeaderAreaExporting += new EventHandler<HeaderAreaExportingEventArgs>(exporter_HeaderAreaExporting);
... and then add some additional formatting on Workbook object that is being created, using the event arguments
void exporter_HeaderAreaExporting(object sender, HeaderAreaExportingEventArgs e)
{
foreach (var field in e.FieldLayout.Fields)
e.Workbook.Worksheets[0].Columns[field.Index].SetWidth(field.LabelWidthResolved, WorksheetColumnWidthUnit.Point);
}
If you need more help, you can write back or if possible attach a sample, so that I can eventually get deeper,
Thanks,
Stefana