WPF:为未从控件继承的元素定义 "Templates"

WPF: Defining "Templates" for Elements Not Inherited From Control

this post 中,我试图找到一种方法来重新模板化 FlowDocument 的内容。我做了几个小时的研究,最终在 Control.Template 属性:

上找到了这份文档

The ControlTemplate specifies the appearance of a Control; if a Control does not have a ControlTemplate, the Control will not appear in your application.

我叫恶作剧

ParagraphRunSectionListTable 等等所有 "appear in my application" 但由于它们继承自System.Windows.ContentElement 而不是 System.Windows.Controls.Control none 他们有一个 Template 属性 我可以用它来重新定义控件的可视化树。

有什么办法可以改变这些元素的视觉呈现方式吗?

无法对 ContentElement 进行模板化,这不是我们想要的。

但是你可以使用

<BlockUIContainer/>

用于 FlowDocument 中的模板化控件。