How can I create subclass of class Inline ? (the one used in FlowDocument)

不羁岁月 提交于 2019-12-04 05:36:52

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.

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.

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!