RichTextBox Blocks

Hi,

I would like to know if it is possible to make an option that can maybe be exposed to alter the behaviour of the richtextbox. At the moment, when the richtextbox is empty, or if you are on an empty line, the default behaviour when adding InlineUIComponents is to create them as BlockUIContainers. This is very frustrating as I only want my "unique" object to stay a specific size, and to still add text after and before it (like having a small image that you can have in the same line as the text)

What I would like to happen is when I create an InlinUIContainer on a blank line, is instead of making it a BlockUIContainer, create a paragraph and add it as an inline, so that I don't have to do post processing work to get it to work the way I want it to. (This will obviously be the property exposed).

It would be great if this could be possible.

Thank you very much,

Jaco

[925 byte] By [CodeDjinn] at [2007-12-23]
# 1

If the caret is on a new line, a paragraph is already created. So adding an inlineUIContainer should be fine.

When the richtextbox is empty there are no blocks - and an inlineUIContainer is placed in the generic BlockUIContainer. You can create an initial paragraph and then add the inlines.

lester-MSFT at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 2

I wish this is how it worked, but it doesn't.

I always initialize the richtextbox with a paragraph, and yes when a new line is created, it is a paragraph, but if the paragraph is empty (no text entered), and the first entry in the paragraph is an InlinUIContainer, the richtextbox converts the paragraph to that generic BlockUIContainer you just described. This is most frustrating. I have worked around this limitation by doing post-processing, but its getting resource intensive, and I would like to have it behave the way you just described :).

Thank you very much,

Jaco

CodeDjinn at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 3
on performing

rtb.Document.Blocks.Add(new Paragraph(new InlineUIContainer(new Button())));

which is the same as your scenario - I get an inline and can type after the button.

lester-MSFT at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 4

Ok, try this,

in the RichTextBox's Drop event, I can't create the InlineUIContainer in code because the rtb.CaretPosition isn't updated while dragging data over the rtb, so I can't in the rtb's drop event do:

TextPointer tp = this.Document.CaretPosition; // does not work, because its not updated in the dragover event, so this will point to the last cursor position

rtb.Document.Blocks.Add(new Paragraph(new InlineUIContainer(new Button()), tp));

So at you're suggestion, I have to build the InlineUIContainer in xaml, and add it to the DataObject as DataFormats.Xaml, so that the InlineUIContainer can be created at the correct position when dragging it over the rtb.

So the default behaviour for the rtb to add .Xaml data is to create a generic BlockUIContainer if the paragraph is empty.

Thank you very much,

Jaco

CodeDjinn at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 5
So I am guessing there is no solution to my problem then?
CodeDjinn at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...

Visual Studio Orcas

Site Classified