本文整理汇总了C#中System.Windows.Controls.TextBlock.AssignFont方法的典型用法代码示例。如果您正苦于以下问题:C# TextBlock.AssignFont方法的具体用法?C# TextBlock.AssignFont怎么用?C# TextBlock.AssignFont使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.TextBlock
的用法示例。
在下文中一共展示了TextBlock.AssignFont方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FormatData
public Table FormatData(DataView data, IEnumerable<PrintColumnInfo> columnsInfo, double width)
{
var contentTable = new Table();
//find the longes columns values from the data
Dictionary<PrintColumnInfo, string> columnsMaxValues = GetCellMaxLengthRow(data, columnsInfo);
//Compute columns width in UI Grid first and than use them in FlowDocument Table
/* Unfortunately Table element from FlowDocument does not support auto column widthes
* and Grid elemend could not be printed on multiple pages.
* That's why I used "doble rendering" trick. First render text in UI and store columns
* width and then use determined columns width in FlowDocument Table
*/
//Creating fake grid to determing columns width
var fakeGrid = new Grid();
// creting real data width on print page
fakeGrid.Width = width;
//setting width of the UI Grid columns
foreach (PrintColumnInfo colInfo in columnsInfo)
{
var colDef = new ColumnDefinition();
colDef.Width = PrintLengthToGridLengthConverter.Convert(colInfo.ColumnWidth);
fakeGrid.ColumnDefinitions.Add(colDef);
}
// adding header row and content row to the grid
// as content width could be smaller than header width
var headerRow = new RowDefinition();
headerRow.Height = GridLength.Auto;
fakeGrid.RowDefinitions.Add(headerRow);
var contentRow = new RowDefinition();
contentRow.Height = GridLength.Auto;
fakeGrid.RowDefinitions.Add(contentRow);
//adding content and header to the UI grid
int counter = 0;
foreach (var columnInfo in columnsMaxValues)
{
//add header
var tbHeader = new TextBlock();
tbHeader.Padding = new Thickness(2);
tbHeader.AssignFont(HeaderFont);
tbHeader.Text = columnInfo.Key.ColumnHeader;
fakeGrid.Children.Add(tbHeader);
Grid.SetColumn(tbHeader, counter);
Grid.SetRow(tbHeader, 0);
//add data
var tbContent = new TextBlock();
tbContent.Padding = new Thickness(2);
tbContent.AssignFont(TableCellFont);
tbContent.Text = columnInfo.Value;
fakeGrid.Children.Add(tbContent);
Grid.SetColumn(tbContent, counter);
Grid.SetRow(tbContent, 1);
counter++;
}
// Fake rendering. It causes grid to calculate its children size
// without doing actual rendering
fakeGrid.Measure(new Size(width, double.MaxValue));
fakeGrid.Arrange(new Rect(new Size(width, double.MaxValue)));
//getting columns width
var columnWidthes = new double[columnsMaxValues.Count];
for (int i = 0; i < columnWidthes.Length; i++)
{
columnWidthes[i] = fakeGrid.ColumnDefinitions[i].ActualWidth;
}
int columnCount = columnsInfo.Count();
// adding column and setting their width
for (int i = 0; i < columnCount; i++)
{
var tableColumn = new TableColumn();
tableColumn.Width = new GridLength(columnWidthes[i]);
contentTable.Columns.Add(tableColumn);
}
//adding headers for column
contentTable.RowGroups.Add(new TableRowGroup());
contentTable.RowGroups[0].Rows.Add(new TableRow());
TableRow currentRow = contentTable.RowGroups[0].Rows[0];
foreach (PrintColumnInfo column in columnsInfo)
{
currentRow.Cells.Add(new TableCell(new Paragraph(new Bold(new Run(column.ColumnHeader)))));
}
//adding Blue line
contentTable.RowGroups[0].Rows.Add(new TableRow());
currentRow = contentTable.RowGroups[0].Rows[1];
var lineCell = new TableCell();
lineCell.ColumnSpan = columnCount;
lineCell.BorderThickness = new Thickness(0, 2, 0, 0);
lineCell.BorderBrush = Brushes.Blue;
currentRow.Cells.Add(lineCell);
int colorCount = 0;
// adding data to the table
foreach (DataRowView dataRowView in data)
{
currentRow = new TableRow();
currentRow.Background = ++colorCount%2 == 0 ? Brushes.LightGray : Brushes.White;
//.........这里部分代码省略.........