2015-01-11 40 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