如何重置TextRange以仅选择RichTextBox中的最后一个选择?

时间:2016-03-24 17:14:14

标签: wpf selection richtextbox textcolor textrange

我正在使用wpf和visual basic。当我在RichTextBox中选择文本时,我使用TextRange:

dim selection1 as New TextRange(Richtextbox.selection.start,Richtextbox.selection.end)

随后:

selection1.ApplyPropertyValue(ForegroundProperty, brushes.Red)

当我多次标记文本时,颜色也会在之前的选择中发生变化。我想改变颜色只有最后选择。怎么做?

1 个答案:

答案 0 :(得分:0)

为什么不缓存之前的选择和以前的颜色?

RichTextBox.BeginChange();
selection?.ApplyPropertyValue(ForegroundProperty, lastColor);
selection = RichTextBox.Selection;
selection.ApplyPropretyValue(ForegroundProperty, newColor);
RichTextBox.EndChange();