使用 wpf 中的自定义 TextElements 扩展 FlowDocument [英] Extending a FlowDocument with custom TextElements in wpf

查看:18
本文介绍了使用 wpf 中的自定义 TextElements 扩展 FlowDocument的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过创建我自己的 Span 和 Run 派生来扩展 FlowDocument 的功能.

I'd like to extend the functionality of the FlowDocument by creating my own derivatives of Span and Run.

这可能吗,有没有人找到任何例子?

Is this possible and has anyone found any examples?

推荐答案

Microsoft 没有公开呈现自定义 TextElement 在他们的文档类之一中.如果您查看运行 或 Span 没有实际渲染代码.渲染发生在 UIElement 由各种内部类(如 FixedTextBuilder).

Microsoft did not expose the methods required to render a custom TextElement inside one of their document classes. If you look at the code for a Run or Span there is no actual rendering code. The rendering takes place in UIElement's built by various internal classes (like FixedTextBuilder).

来自 MSDN 关于 FrameworkContentElement 的注释:

From MSDN's notes on FrameworkContentElement:

FrameworkContentElement 还没有定义自己的渲染行为;可以在代码或标记中实例化实际的 FrameworkContentElement 类实例,但在 WPF 应用程序用户界面 (UI) 中不显示任何内容.呈现逻辑必须由将 FrameworkContentElement 子元素作为其内容模型的一部分的类或在 FrameworkContentElement 派生类中提供.

FrameworkContentElement does not yet define its own rendering behavior; instantiating an actual FrameworkContentElement class instance in code or markup is possible but displays nothing in a WPF application user interface (UI). Rendering logic must be provided by classes that take FrameworkContentElement child elements as part of their content model, or in FrameworkContentElement derived classes.

一切都没有丢失,通过 BlockUIContainerInlineUIContainer 类.然后,您可以创建一个低级别的 UIElement,它将托管在固定或流文档中,或者使用更高级别的 WPF 元素.

All is not lost, support for rendering custom Block and Inline elements is provided through the BlockUIContainer and InlineUIContainer classes. You could then create a low level UIElement which would be hosted inside the fixed or flow document, or use higher level WPF elements.

这篇关于使用 wpf 中的自定义 TextElements 扩展 FlowDocument的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆