Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create in a comfortable way FlowDocuments by code with WPF?
    primarykey
    data
    text
    <p>I need to generate some reports and the selected format has been FlowDocuments. As I'm generating them thru code I find myself all the time doing things like this:</p> <pre><code>list.ListItems.Add(new ListItem(new Paragraph(new Run(string.Format("XXX XXXXXX: {0}", _result.XXX.Count))))); list.ListItems.Add(new ListItem(new Paragraph(new Run(string.Format("XXX XXXXXX: {0}", _result.XXX()))))); list.ListItems.Add(new ListItem(new Paragraph(new Run(string.Format("XXX XXXXXX: {0}", _result.LossOperations()))))); </code></pre> <p>When I have to add a single line of text I have to do something like:</p> <pre><code>Paragraph auxParagraph = new Paragraph(); auxParagraph.Inlines.Add("Executing time " + _result.ExecutingTime.ToString()); report.Blocks.Add(auxParagraph); </code></pre> <p>Looks a bit overkill to me. I'm using the API in the right way? All I see documented talks about creating the documents by hand. Maybe they are not intended to be created by code and should we check another format? Or maybe are there other higher level APIs that make the work with the FlowDocuments easier?</p> <p>Thanks!</p> <p>Edit: just another example working with tables:</p> <pre><code>foreach (DateTime availableDay in _result.Generator.AvailableDays) { Table table = new Table(); table.Columns.Add(new TableColumn()); table.Columns.Add(new TableColumn()); table.Columns.Add(new TableColumn()); table.Columns.Add(new TableColumn()); table.Columns.Add(new TableColumn()); TableRowGroup headers = new TableRowGroup(); TableRow headersRow = new TableRow(); headersRow.Cells.Add(new TableCell(new Paragraph(new Run("XXX XXXX")))); headersRow.Cells.Add(new TableCell(new Paragraph(new Run("XXX XXXX")))); headersRow.Cells.Add(new TableCell(new Paragraph(new Run("XXX XXXX")))); headersRow.Cells.Add(new TableCell(new Paragraph(new Run("XXX XXXX")))); headersRow.Cells.Add(new TableCell(new Paragraph(new Run("XXX XXXX")))); headers.Rows.Add(headersRow); table.RowGroups.Add(headers); DateTime day = availableDay; TableRowGroup valuesGroup = new TableRowGroup(); foreach (Operation operation in dailyOperations) { TableRow row = new TableRow(); row.Cells.Add(new TableCell(new Paragraph(new Run("XXX XXXX")))); row.Cells.Add(new TableCell(new Paragraph(new Run("XXX XXXX")))); row.Cells.Add(new TableCell(new Paragraph(new Run("XXX XXXX")))); row.Cells.Add(new TableCell(new Paragraph(new Run("XXX XXXX")))); row.Cells.Add(new TableCell(CreateColoredValue(operation.Result))); valuesGroup.Rows.Add(row); } table.RowGroups.Add(valuesGroup); result.Blocks.Add(table); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload