How can I change color of each character of TextBlock (or RichTextBlock, RichEditBox, ...) in UWP? I need to look for specific characters in the text and change their color, something like this:
I saw this link but that method is good for English words, not Arabic / in English characters, each character is different from the other characters and changing the color of each character is not a difficult task
textBlock1.Inlines.Clear();
Run run1 = new Run
{
Text = "A",
Foreground = new SolidColorBrush(Colors.Red)
};
textBlock1.Inlines.Add(run1);
Run run2 = new Run
{
Text = "B",
Foreground = new SolidColorBrush(Colors.Green)
};
textBlock1.Inlines.Add(run2);
Run run3 = new Run
{
Text = "C",
Foreground = new SolidColorBrush(Colors.Blue)
};
textBlock1.Inlines.Add(run3);
Result :
But this is not the case with Arabic characters, and the characters are usually connected to each other, and when I change the color of a character, everything breaks down:
first code for Arabic [ no problem ]:
second code for Arabic [ first problem - cant change color of vowels ]:
note : vowels characters width is zero
While my text should be displayed as follows :
next problem : in this section i dont whant change color of vowels, i whant change color of arabic characters, in font-nabi defined if
In the font that I use (most Arabic fonts are usually the same) it is defined that if two specific characters are placed next to each other, the shape of the character will change, See this font :
I can not even change the color of these characters, The color of character 1 became the same as 2!, While according to the code we expected the color of the first character to be red and the next to be green :