Search code examples
wpfbuttontextrichtextboxuielement

Place UIElement and Text in same line in RichTextbox


How to place text and Button in a same line in WPF Richtextbox?

In the image below some texts and a button control are placed in a richtextbox.

enter image description here

I want some texts to be placed before and after the button in the same line.

Is it possible to define some width to the blockuicontainer or a wayout to achieve the same?

What I want is:

enter image description here


Solution

  • I have added a FlowDocument to the RichTextBox and a Paragraph to the FlowDocument.

    Sample code is:

    Paragraph para = new Paragraph();
            FlowDocument fd = new FlowDocument();
            fd.Blocks.Add(para);
            txtExpression.Document = fd;
            para.Inlines.Add(new Button() { Content = "Hello!" });