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
.
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.
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.
If you want to know why I want to create custom Inline
element have a look on question Create guitar chords editor in WPF.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With