繁体   English   中英

如何从文本中的给定位置获取字符的颜色?

[英]How can I get the color of a character from a given position in a text?

我基本上想检查文本中给定位置的字符是否是某种颜色。 例如

if(character.inAposition == blue){
   change characters color
}

这就是我最初更改文字颜色的方式

TextPointer start = position.GetPositionAtOffset(indexInRun);
TextPointer end = start.GetPositionAtOffset(word.Length);
TextRange rangeText = new TextRange(start, end);
rangeText.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Blue);

其中indexInRun是与“ word”匹配的任何子字符串的起始索引

您不能检查字符。 您可以检查RichTextBox Inlines集合的Run元素。 但是您必须检查它是否确实是Run或其他内容,例如完整的TextBlock或Image等。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM