BoldSignEasily embed eSignatures in your .NET applications. Free sandbox with native SDK available.
dataGrid.PrintSettings.PrintManagerBase = new CustomPrintManagerBase(dataGrid);
dataGrid.PrintSettings.AllowPrintByDrawing = false;
dataGrid.PrintSettings.AllowPrintStyles = true;
dataGrid.ShowPrintPreview();
public class CustomPrintManagerBase : GridPrintManager
{
public CustomPrintManagerBase(SfDataGrid dataGrid) : base(dataGrid)
{
}
protected override object GetColumnElement(object record, string mappingName)
{
var columnElement = base.GetColumnElement(record, mappingName) as TextBlock;
if (columnElement != null)
columnElement.Foreground = new SolidColorBrush(Colors.Blue);
return columnElement;
}
protected override void AddDataRowToPanel(PrintPagePanel panel, RowInfo rowInfo)
{
base.AddDataRowToPanel(panel, rowInfo);
var topThickNess = rowInfo.NeedTopBorder ? 1 : 0;
var bottomThickness = rowInfo.NeedBottomBorder ? 1 : 0;
var record = (rowInfo.Record is RecordEntry) ? (rowInfo.Record as RecordEntry).Data : rowInfo.Record;
var i = 0;
foreach (var cellInfo in rowInfo.CellsInfo)
{
var cell = GetPrintGridCell(record, cellInfo.ColumnName);
cell.Width = cellInfo.CellRect.Width;
cell.Height = cellInfo.CellRect.Height;
cell.BorderThickness = i == 0 ?
new Thickness(1, 0, 0, 1) : i == dataGrid.Columns.Count - 1 ? new Thickness(0, 0, 1, 1) : new Thickness(0, 0, 0, 1);
var content = GetColumnElement(record, cellInfo.ColumnName);
if (content is DataTemplate)
{
cell.ContentTemplate = content as DataTemplate;
SetDataTemplateContentToPrintGridCell(cell, cellInfo, record);
}
else
cell.Content = content;
cellInfo.Element = cell;
panel.Children.Add(cell);
i++;
}
}
internal void SetDataTemplateContentToPrintGridCell(ContentControl cell, CellInfo cellInfo, object record)
{
cell.Content = record;
}
} |
protected override double GetColumnWidth(string mappingName)
{
if (mappingName == "EmployeeArea")
return this.dataGrid.Columns[mappingName].ActualWidth;
return base.GetColumnWidth(mappingName);
} |
protected override object GetColumnElement(object record, string mappingName)
{
var columnElement = base.GetColumnElement(record, mappingName) as TextBlock;
if (columnElement != null)
{
columnElement.Foreground = new SolidColorBrush(Colors.Blue);
columnElement.TextWrapping = TextWrapping.Wrap;
}
return columnElement;
} |