private void dgTables_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { RulesTable rt = (RulesTable)dgTables.CurrentItem; if (rt != null) { TablesView.Document = FlowDocumentConverter.AsFlowDocument(rt); } }
public static IEnumerable <RulesTable> ParseFile(string file) { string[] lines = file.Split('\n');// File.ReadAllLines(file); int c = 0; string line; while (c < lines.Count()) { line = lines[c].Trim(); // "!---" marks start of dataset if (line == "!---") { RulesTable rt = new RulesTable(); rt.Rows = new List <string>(); // next line is the name of table. c += 1; rt.Name = lines[c].Trim(); //next line contains the headers separated by '|'. c += 1; rt.Headers = lines[c].Trim().Split('|'); c += 1; // "EndTable" marks end of actual table while (lines[c].Trim() != "EndTable") { // get the rows of the table. rt.Rows.Add(lines[c].Trim()); c += 1; } c += 1; // "---!" marks end of dataset // between "Endtable" and "---!" may be additional text. while (lines[c].Trim() != "---!") { rt.AdditionalText.Add(lines[c].Trim()); c += 1; } yield return(rt); } c += 1; } }
public static FlowDocument AsFlowDocument(RulesTable rt) { FlowDocument fd = NewFlowDocument(false, false); Paragraph titel = new Paragraph(); titel.FontWeight = FontWeights.Bold; titel.Inlines.Add(rt.Name); fd.Blocks.Add(titel); // Create the Table... Table table = new Table(); table.BorderBrush = new SolidColorBrush(Colors.Black); table.BorderThickness = new Thickness(1.0); // ...and add it to the FlowDocument Blocks collection. fd.Blocks.Add(table); // Set some global formatting properties for the table. int numberOfColumns = rt.Headers.Count(); for (int x = 0; x < numberOfColumns; x++) { table.Columns.Add(new TableColumn()); } // Create and add an empty TableRowGroup to hold the headers. table.RowGroups.Add(new TableRowGroup()); table.RowGroups[0].Rows.Add(new TableRow()); for (int h = 0; h < rt.Headers.Count(); h++) { TableCell headerCell = new TableCell(new Paragraph(new Run(rt.Headers[h]))); /*headerCell.BorderBrush = new SolidColorBrush(Colors.Black); * headerCell.BorderThickness = new Thickness(1.0);*/ table.RowGroups[0].Rows[0].Cells.Add(headerCell); } table.RowGroups[0].FontSize = 12; foreach (string row in rt.Rows) { TableRow currentRow = new TableRow(); table.RowGroups[0].Rows.Add(currentRow); foreach (string cell in row.Split('|')) { TableCell rowCell = new TableCell(new Paragraph(new Run(cell))); /*rowCell.BorderBrush = new SolidColorBrush(Colors.Black); * rowCell.BorderThickness = new Thickness(1.0); * rowCell.Padding = new Thickness(0);*/ currentRow.Cells.Add(rowCell); } } for (int x = 1; x < table.RowGroups[0].Rows.Count(); x++) { // Set alternating background colors for the middle colums. if (x % 2 == 0) { table.RowGroups[0].Rows[x].Background = Brushes.Beige; } else { table.RowGroups[0].Rows[x].Background = Brushes.LightSteelBlue; } } foreach (string at in rt.AdditionalText) { Paragraph t = new Paragraph(); t.FontSize = 10; t.Inlines.Add(at); fd.Blocks.Add(t); } return(fd); }