In a FlowDocument / WPF RichtTextBox the Parent
property is of type DependencyObject
. But I haven't found any meaningful case where Parent isn't a FlowDocument
(or null
).
Is there any?
Edit:
Why I need to know that?
My method gets a Paragraph
as parameter and I don't know when it is called.
When Parent is null
I know that the Paragraph is not integrated in any structure.
When parent is FlowDocument
, I have to take that in account for my operations.
Do I have also take in account that it may be different from null
or FlowDocument
?
Documentation for Paragraph clearly says:
Parent - Gets the parent in the logical tree for this element. (Inherited from FrameworkContentElement)
So it is inherited property, which is bound to have common base type and for Paragraph in reasonable cases will contain FlowDocument
object.
Paragraph.Parent is not necessary FlowDocument. In the example from FlowDocument Table official tutorial, the Parent of new Paragraph(new Run("2004 Sales Project"))
paragraph is a TableCell
:
// Create and add an empty TableRowGroup to hold the table's Rows.
table1.RowGroups.Add(new TableRowGroup());
// Add the first (title) row.
table1.RowGroups[0].Rows.Add(new TableRow());
// Alias the current working row for easy reference.
TableRow currentRow = table1.RowGroups[0].Rows[0];
// Global formatting for the title row.
currentRow.Background = Brushes.Silver;
currentRow.FontSize = 40;
currentRow.FontWeight = System.Windows.FontWeights.Bold;
// Add the header row with content,
currentRow.Cells.Add(new TableCell(new Paragraph(new Run("2004 Sales Project"))));
// and set the row to span all 6 columns.
currentRow.Cells[0].ColumnSpan = 6;