Kapparino
Kapparino

Reputation: 988

How to clear all properties from Paragraph.Inline

Is it possible to clear all properties like (background color...) from Paragraph.Inline elements, just like you can do with class TextRange ?


Well, I wanted to clear background propery from previous Run element from Inline Collection. So I thought it would be easier to call a method which would clear all previous properties. However, in my case, it seems the only way to do this is something like this:

int index = 0;
...
List<Inline> runList = ParagraphComponent.Inlines.ToList(); 
if (index < runList.Count) {
    if (index > 1) {
       int previousPartIndex = index - 2;
       if (!string.IsNullOrEmpty(runList[previousPartIndex].Text)) {
          runList[previousPartIndex].Background = null;
       }
    }
    runList[index].Background = BackgroundColor;
    index += 2;
}

Upvotes: 0

Views: 449

Answers (1)

Clemens
Clemens

Reputation: 128060

As you can't access the InlineCollection by index, I'd suggest to use the original _inlineCollection from which you initialize the Paragraph's Inlines (from your previous question).

((Run)_inlineCollection[index]).Background = null;
index++;
while (index < inlineCollection.Count && !(_inlineCollection[index] is Run))
{
    index++;
}
if (index < _inlineCollection.Count)
{
    ((Run)_inlineCollection[index]).Background = BackgroundColor;
}

Upvotes: 1

Related Questions