I needed this code as you cannot insert new lines with indent properties. Only paragraphs can have indent properties.
So why not use a paragraph you say? Well, I needed to be able to wrap custom annotations around multiple lines which cannot be done with Paragraphs.
Main Method: When inserting into the document you will need to change the Style that I have used (see inside the while loop). My style just highlights the blank padding so I can visually see what's going on.
Here's my Span Style to highlight the new line padding as I previously mentioned:
I hope this helps you.
Please let me know if you know of a better way to achieve this.
6 Answers, 1 is accepted
The approach you've taken seems to be correct. The only improvement we could suggest is to use one instance of the LineBreakSpacing style instead of creating a new instance for every inserted space. Ultimately, you can add all the styles you need when initializing the document and then get them form the document's StyleRepository by name when you need them.Kind regards,
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
I do find there is a little performance lag when inserting a lot of character spaces towards the end of a given line.
I will post my update when I have done it.
I'm having trouble applying the span style from the repository. I can get it to work with Paragraphs but not spans.
Here's my code.
Add styles to repository:
LineBreak Style Definition:
Insert LineBreak With Spacing:
Any ideas why the style won't set to the linebreak and padding spans?
As I previously mentioned, I can apply styles to Paragraphs using the StyleRepository but not spans.
Thanks for your time,
This bit of code sets the style:
However, it doesn't apply it correctly to my span with the padding spaces. It is setting the style to the spans either side of the NewLineSpacing.
Here's the updated InsertNewLine method:
I should have done this instead:
However, when I continue to type after the LineBreakSpacing, the style shouldn't be applied to the typed text. It should only be applied to the LineSpacingSpan.
Here's my XAML output before line spacing:
Here's my XAML output after line spacing:
This is my desired XAML when Linespacing:
I have also attached an image of what my output look likes (this isn't how I want it to be).
Here's the final working method (please let me know if there's a better way to apply the span style):
See the attached image for a Snap show of my document.