【问题标题】:Is there any meaningful use where the Paragraph.Parent property is not a FlowDocument?在 Paragraph.Parent 属性不是 FlowDocument 的情况下,是否有任何有意义的用途?
【发布时间】:2019-09-06 17:52:31
【问题描述】:

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

有吗?

编辑:

为什么我需要知道这些?

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

当 Parent 是 null 时,我知道 Paragraph 没有集成到任何结构中。

当父母是FlowDocument 时,我必须考虑到我的操作。

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

【问题讨论】:

  • 请告诉我这个问题有什么问题。

标签: c# wpf richtextbox flowdocument


【解决方案1】:

Paragraph 的文档清楚地表明:

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

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


Paragraph.Parent 不是必须的 FlowDocument。在FlowDocument Table official tutorial 的示例中,new Paragraph(new Run("2004 Sales Project")) 段落的 Parent 是 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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-22
    • 1970-01-01
    • 1970-01-01
    • 2021-04-20
    • 1970-01-01
    • 2023-03-24
    • 2023-01-07
    • 2022-10-30
    相关资源
    最近更新 更多