简体   繁体   English

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

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

I basically want to check whether a character in a given position in a text is a certain color. 我基本上想检查文本中给定位置的字符是否是某种颜色。 For example 例如

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

that's how I initially change the text color 这就是我最初更改文字颜色的方式

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

where indexInRun is the starting index of any substring that matches "word" 其中indexInRun是与“ word”匹配的任何子字符串的起始索引

You cant check a character. 您不能检查字符。 you can check a Run element of the RichTextBox Inlines collection. 您可以检查RichTextBox Inlines集合的Run元素。 But you have to check if it really is a Run or something else like a complete TextBlock, or Image, etc. 但是您必须检查它是否确实是Run或其他内容,例如完整的TextBlock或Image等。

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

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