Category / Section
How to print display value of GridTemplateColumn in WPF DataGrid (SfDataGrid)?
1 min read
You can print a displayed data except GridTemplateColumn CellTemplate and changed it format by overriding the GetColumnElement in GridPrintManager class in WPF DataGrid (SfDataGrid).
protected override object GetColumnElement(object record, string mappingName) { var column = dataGrid.Columns[mappingName]; if (column.CellTemplate == null) return base.GetColumnElement(record, mappingName); else { var tb = new TextBlock { VerticalAlignment = VerticalAlignment.Center, TextAlignment = GetColumnTextAlignment(mappingName), TextWrapping = GetColumnTextWrapping(mappingName), FlowDirection = PrintFlowDirection, DataContext = record }; tb.SetBinding(TextBlock.TextProperty, column.DisplayBinding); decimal value; decimal.TryParse(tb.Text, out value); tb.Text = value.ToString("F3"); var padding = column.ReadLocalValue(GridColumn.PaddingProperty); tb.Padding = padding != DependencyProperty.UnsetValue ? column.Padding : new Thickness(4, 3, 3, 1); return tb; } }