WPF RichTextbox 从 TextRange 中删除前景信息

Leo*_*Leo 1 wpf dependency-properties richtextbox

抱歉我的英语不好...RichTextBox内容的默认值是从其RichTextBox自身继承前景色。这很好,但如果我Foreground为我的文本的某些部分设置了特定的颜色,那部分显然不再继承Foreground。如何让我的“彩色”文本Foreground再次继承?我正在尝试执行 Office Word 中的“自动”颜色之类的操作,但是在将特定颜色设置为 a 后TextRange,我不知道如何取消设置:/

TextRange.ClearAllProperties()做我需要的,但也会删除其他属性,比如FontSizeFontFamily......

TextRange.ApplyPropertyValue(ForegroundProperty, DependencyProperty.UnsetValue) 也没有做的伎俩......

jml*_*kin 6

您还可以通过将属性设置为 null 来取消设置(这对我清除背景有用,例如删除突出显示)

TextRange.ApplyPropertyValue(TextElement.BackgroundProperty, null);