1

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:

enter image description here


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 :

enter image description here

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 ]:

enter image description here

second code for Arabic [ first problem - cant change color of vowels ]:

note : vowels characters width is zero

enter image description here

While my text should be displayed as follows : enter image description here

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 : enter image description here

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 : enter image description here

Mahdi
  • 33
  • 1
  • 7
  • Have you tried with any code? If no, do try first. If yes, edit the question and share the code you have tried. – Sнаđошƒаӽ Jan 09 '21 at 05:12
  • Does this answer your question? [Change color in part of text in textblock](https://stackoverflow.com/questions/26907164/change-color-in-part-of-text-in-textblock) – Sнаđошƒаӽ Jan 09 '21 at 05:13
  • ty for answer, yea I tested several code - but... I edit my post, pls see. – Mahdi Jan 09 '21 at 13:34
  • Quite a long time ago I tried doing something similar but in html, trying to color just the diacritics. I don't think I succeeded in doing it the way I wanted, so eventually I ended up using a tooltip to serve my purpose. Yes, setting color for individual characters separates them. But most Arabic letters have multiple code points, meaning different characters really, for various forms of the same character when used in different joined forms. You could look into that. Good luck! – Sнаđошƒаӽ Jan 09 '21 at 14:47

0 Answers0