Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
145341 | Jun 18,2019 09:06 AM UTC | Jun 24,2019 08:43 AM UTC | WPF | 7 |
![]() |
Tags: SfDataGrid |
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;
} |
This post will be permanently deleted. Are you sure you want to continue?
Sorry, An error occured while processing your request. Please try again later.
This page will automatically be redirected to the sign-in page in 10 seconds.