1

I have an RTB with InlineUIContainer's. I store them in a List, so I can access them directly. How can I remove them from my RTB in C#?

Code example:

// for some TextPointer textPointer in my RTB

TextBlock tb = new TextBlock();
tb.Text = "hello world";

InlineUIContainer inlineUIContainer = new InlineUIContainer(tb, textPointer);
tb_list.Add(inlineUIContainer);
JessMcintosh
  • 460
  • 2
  • 6
  • 21

1 Answers1

2

Here, you can remove it like below. If this is your local collection of containers:

            List<InlineUIContainer> containers = new List<InlineUIContainer>();

and you want to remove the container which is first in your list then:

            InlineUIContainer inlineContainer = containers[0] ;    
            foreach (var block in myRTB.Document.Blocks)
            {
                if (block is Paragraph)
                {
                    var paragraph = block as Paragraph;

                    if (paragraph.Inlines.Contains(inlineContainer))
                    {
                        paragraph.Inlines.Remove(inlineContainer);
                    }
                }
            }
Nitin
  • 18,344
  • 2
  • 36
  • 53