0

Is there a way to insert white space of given width to FlowDocument as Inline ? So that I can 'indent' some other Inlines as I want.

If it was possible to place some inline on some x-offset in the line that would also solve the problem.

NOTE: the purpose of this would be solving partial problem of the problem described in this question.

Community
  • 1
  • 1
Rasto
  • 17,204
  • 47
  • 154
  • 245

2 Answers2

2

You could use the container classes, e.g.:

<RichTextBox>
    <FlowDocument>
        <Paragraph>
            <InlineUIContainer>
                <FrameworkElement Width="200"/>
            </InlineUIContainer>
            <Run x:Name="RunChan" Text="Indented Text"/>
        </Paragraph>
    </FlowDocument>
</RichTextBox>

I would not really recommend it though.


In a TextBlock:

<TextBlock>
    <InlineUIContainer>
        <FrameworkElement Width="200"/>
    </InlineUIContainer>
    <Run x:Name="RunChan" Text="Indented Text"/>
</TextBlock>
H.B.
  • 166,899
  • 29
  • 327
  • 400
  • 2 problems here: First the `Run` containing text `Blah blah blah` can be wrapped to the next line and in that case I'll have empty white line there. Second `` is not supported by `TextBlock` (I can still use it with `FlowDocument`). – Rasto Apr 26 '11 at 23:29
  • 1
    My textblocks support it (added that to the answer) – H.B. Apr 26 '11 at 23:32
  • H.B.: Then I was wrong... Why wouldn't you recommend it? I know it is not clear but do you have any particular reason? Can you thing of a a better solution in context of [this question](http://stackoverflow.com/questions/5796457/create-guitar-chords-editor-in-wpf-from-richtextbox) (white space is meant to indent chords so that they appear over right lyrics character) ? – Rasto Apr 26 '11 at 23:44
  • 1
    I do not like it because i consider it a bit of a hack to insert a dummy control for spacing. If you had Blocks at your disposal you could use their `Margin` property, too bad Inlines do not have that. By the way, the comment link syntax can be found by clicking the help button when creating a comment – H.B. Apr 26 '11 at 23:46
  • H.B.: I wander why they do not have margin property? Do you think I can subclass `Inline` to create something like `SpanWithMargin` class? I would need to be able to influence how `Inline`s are laid to do it. Or at least to control how much space they occupy. Add link: I have corrected the link, I had to goggle for syntax, never mentioned the help link before. – Rasto Apr 26 '11 at 23:54
  • I tried subclassing inlines before, it did not work out very well since i had no clue what i was supposed to do. You can try but i cannot help you. – H.B. Apr 26 '11 at 23:58
  • H.B.: I do not quite understand your last comment. You tried to subclass `Inline` to give an answer to my question but you did not succeed because you did not know what I wanted it to do? Or you have tried to to subclass `Inline` before from some other reason but you did not succeed because you did not know how to subclass it? – Rasto Apr 27 '11 at 00:17
  • The latter, i did not know how to properly subclass it. – H.B. Apr 27 '11 at 01:05
  • @drasto H.B. 's answer the best you will get, and I don't really consider it being a hack. It just is what it is: a whitespace inline with a specific width. With this you get all you're asking for. If wrapping was a problem for you, just prevent the wrapping, but then you'll have long lines. if you want to have a whole paragraph indented do as H.B. suggested: use a Margin. – Markus Hütter May 01 '11 at 12:31
0

I'm not sure if this will solve your problem, but if you want to "indent" an Inline, perhaps you can insert a small Floater or Figure sized to what you need. Make sure the Floater is short so that it doesn't span more than a single line.

I'm looking for something more elegant than this myself, but this is working for me in the meanwhile.

Kevin Hsu
  • 1,726
  • 11
  • 14
  • Well this is an option but not very clear one... And not clear solutions tent to by buggy. If I use `Figure` and not `Floater` it cannot span to the next line is that right ? Well if you find something usefull or get any idea please let me know. You will also find my advances here. It would be great if there was something like property `MinimumXOffset` in class `Span`. Or if there was a way to subclass it and implement such property. – Rasto Apr 26 '11 at 22:31
  • 1
    Will do - one big wish of mine is for Microsoft to formalize and surface how FlowDocument elements are formatted so that we can implement our own Inlines and Blocks the same way we create custom FrameworkElements. – Kevin Hsu Apr 26 '11 at 23:47
  • So we cannot implement our own `Inline`s now ? Or we just don't know how because it is documented ? I was thinking that creating my own `Inline` is the only way out from this inline hell... – Rasto Apr 27 '11 at 00:13
  • 1
    Not sure, but I think the rendering behavior is specific to the set of FlowDocument classes. In other words, the renderer of the FlowDocument seems to interpret how to render the elements with its own code rather than deferring it to code inside the elements. If you use Reflector on some of the elements, they contain nothing in the way of actual formatting. – Kevin Hsu Apr 28 '11 at 06:38