2015-01-11 42 views
0

是否可以像Paragraph.Inline元素一样清除所有属性(如背景颜色...),就像使用类TextRange一样?如何清除段落中的所有属性。inline


那么,我想清除从以前的运行元素Inline集合背景propery。所以我觉得调用一个可以清除以前所有属性的方法会更容易。 然而,在我的情况,似乎要做到这一点是这样的唯一途径:

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; 
} 
+0

[你尝试过什么?](http://mattgemmell.com/what-have-you-tried/) – Clemens

+0

克莱门斯嗨!请检查编辑后!附:这只是我复杂的东西,或FlowDocument,Inline组件requries一些练习时间或它真的很复杂? – Kapparino

回答

1

正如你不能访问由指数InlineCollection,我建议使用原来的_inlineCollection从中初始化段落的内联(从您的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; 
} 
+0

再次感谢你! '((Run)_inlineCollection [index])。BringIntoView();'这也起作用了! – Kapparino