如何创建类内联的子类? (在FlowDocument的使用的)子类、内联、FlowDocument

2023-09-03 07:34:15 作者:香烟美酒篮子与狗。

在WPF中,我想创建自定义 内联 实施。从 内联 :一个抽象类,它提供了所有的内联流内容元素的基地如 类图运行 或的 跨度 从的 内联

In WPF I would like to create custom Inline implementation. From documentation of Inline: "An abstract class that provides a base for all inline flow content elements." Classes like Figure, Run or Span inherit from Inline.

我的自定义类从 内联 会像'2成荫运行。我有特殊需要的流量的文件,这似乎是唯一的出路。但是我不知道从哪里开始: 内联 没有定义任何成员!这是抽象类,因此,就是要继承,但不存在的文件如何从它继承。不要在MSDN和无处哪里可以找到它。

My custom class inheriting from Inline would be something like '2 lined Run'. I have special needs for flow of document and this seems to be the only way. However I don't know where to start: Inline does not define any members! It is abstract class so it is meant to be inherited but there is no documentation on how to inherit from it. Not in MSDN and nowhere else where I could find it.

如果您可以提供一些在线资源(教程/博客/条)或code样本如何创建的 内联 。例如只是一些空洞的宽度和高度框。

If you can provide some on-line resources (tutorial/blog/article) or code sample how to create subclass of Inline. For example just empty box of some width and height.

如果你想知道我为什么要创建自定义的内联元素有问题Create吉他和弦编辑器,在WPF 。

If you want to know why I want to create custom Inline element have a look on question Create guitar chords editor in WPF.

推荐答案

基类可以用于添加类型保真度的单纯的目的。例如,code在FlowDocument的处理器可能只想做code这样的:

Base classes can be used for the mere purposes of adding type fidelity. For example, code in a FlowDocument processor might just want to do code like:

if(currentElement is Inline)
{
   // Do something
}

内嵌实际上并不需要做任何事情。

Inline doesn't actually have to do anything at all.

至于从直插式子类,我想你可能无法达到你想要的东西。我的理解是,FlowDocument的渲染器负责观察他们的言行举止,从它的类型和性质的元素和跨preting的类型。换句话说,它不知道您的自定义code。我认为你能做的最好的是一个有用的元素,以继承和你的子类惹属性值或任何东西是重写。

As far as subclassing from Inline, I think you might not be able to achieve what you want. My understanding is that the FlowDocument renderer is responsible for looking at the types of the elements and interpreting how they behave from its type and its properties. In other words, it has no knowledge of your custom code. I think the best you could do is to subclass from a useful element and have your subclass mess with property values or anything that is overridable.

您可以添加附加属性和方法的子元素定义这些属性了。例如,如果你想要一个超链接容器允许不同的子元素来提供不同的链接,你可以继承从超链接,定义一个新的链接附加属性,和不同的处理click事件的儿童比超链接本身。

You may be able to add attached properties and process child elements defining those properties, too. For example, if you wanted a hyperlink container to allow different child elements to provide different links, you could subclass from Hyperlink, define a new Link attached property, and handle the click events for the children differently than Hyperlink itself.

您可能还可以实现与InlineUIContainer和BlockUIContainer元素,让你嵌入里面任何的UIElement,包括自定义UI元素了一定的成功。

You might also be able to achieve some success with the InlineUIContainer and BlockUIContainer elements, which let you embed any UIElement inside it, including custom UIElements.

 
精彩推荐
图片推荐