2012-09-18 52 views
1

我在Windows 8中使用新的RichEditBox,並嘗試選擇文本範圍並更改文本顏色。下面的代碼將下劃線並更改所選文本的背景,但ForegroundColor不會更改,文本只是保持黑色。在RichEditBox中更改文本顏色

result.Document.SetText(Windows.UI.Text.TextSetOptions.None, "Hello World");    
var range = result.Document.GetRange(0, 5); 

range.CharacterFormat.Underline = Windows.UI.Text.UnderlineType.DoubleWave; 
range.CharacterFormat.ForegroundColor = Windows.UI.Color.FromArgb(255, 0, 0, 255); 
range.CharacterFormat.BackgroundColor = Windows.UI.Color.FromArgb(255, 0, 255, 0); 

如何更改爲RichEditBox內的ITextRange的文本顏色?

回答

2

您需要撥打Document.ApplyDisplayUpdates才能看到對文本的更改。

result.Document.ApplyDisplayUpdates();