在 Paragraph.Parent 属性不是 FlowDocument 的情况下是否有任何有意义的用途?



在 FlowDocument/WPF RichtTextBox 中,Parent属性的类型为DependencyObject。但我还没有发现任何有意义的案例,即父母不是FlowDocument(或null(。

有吗?

编辑:

为什么我需要知道这一点?

我的方法得到一个Paragraph作为参数,我不知道什么时候调用它。

当父级null我知道该段落没有集成到任何结构中。

当父母FlowDocument时,我必须在操作中考虑到这一点。

我是否也考虑到它可能与nullFlowDocument不同?

段落文档明确指出:

父 - 获取此元素的逻辑树中的父级。(继承自 FrameworkContentElement(

所以它是继承的属性,它必然具有共同的基类型,并且在合理的情况下对于段落将包含FlowDocument对象。


Paragraph.Parent 不是必需的 FlowDocument。在 FlowDocument Table 官方教程的示例中,new Paragraph(new Run("2004 Sales Project"))段落的父级是一个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;

相关内容

最新更新