Note that there are some explanatory texts on larger screens.

plurals
  1. POFinding all Images in a FlowDocument
    primarykey
    data
    text
    <p>Since I am pretty new to WPF FlowDocuments I would like to ask if the code below is correct. It is supposed to return all Images contained in a FlowDocument as List:</p> <pre><code>List&lt;Image&gt; FindAllImagesInParagraph(Paragraph paragraph) { List&lt;Image&gt; result = null; foreach (var inline in paragraph.Inlines) { var inlineUIContainer = inline as InlineUIContainer; if (inlineUIContainer != null) { var image = inlineUIContainer.Child as Image; if (image != null) { if (result == null) result = new List&lt;Image&gt;(); result.Add(image); } } } return result; } private List&lt;Image&gt; FindAllImagesInDocument(FlowDocument Document) { List&lt;Image&gt; result = new List&lt;Image&gt;(); foreach (var block in Document.Blocks) { if (block is Table) { var table = block as Table; foreach (TableRowGroup rowGroup in table.RowGroups) { foreach (TableRow row in rowGroup.Rows) { foreach (TableCell cell in row.Cells) { foreach (var block2 in cell.Blocks) { if (block2 is Paragraph) { var paragraph = block2 as Paragraph; var images = FindAllImagesInParagraph(paragraph); if (images != null) result.AddRange(images); } else if (block2 is BlockUIContainer) { var container = block as BlockUIContainer; if (container.Child is Image) { var image = container.Child as Image; result.Add(image); } } } } } } } else if (block is Paragraph) { var paragraph = block as Paragraph; var images = FindAllImagesInParagraph(paragraph); if (images != null) result.AddRange(images); } else if (block is BlockUIContainer) { var container = block as BlockUIContainer; if(container.Child is Image) { var image = container.Child as Image; result.Add(image); } } } return result.Count &gt; 0 ? result : null; } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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