how to get each character of a textblock of different color in wpf?
Asked
Active
Viewed 4.6k times
1 Answers
62
Use many different runs:
<TextBlock FontSize="22">
<Run Foreground="Gold">H</Run>
<Run Foreground="Maroon">e</Run>
<Run Foreground="Blue">l</Run>
<Run Foreground="Orange">l</Run>
<Run Foreground="Brown">o</Run>
</TextBlock>
This produce the result:

Felice Pollano
- 32,832
- 9
- 75
- 115
-
2How can I do this with MVVM? – Mateusz Dembski Jul 16 '13 at 12:48
-
Bind `TextBlock` text to a list of `Runs`? – wingerse Oct 16 '15 at 10:12
-
1@EmpereurAiman You can't bind `List
` to `Text` property of `TextBlock`. But you can bind to `Text` value of individual `Run`. Try: [http://stackoverflow.com/questions/2705444/can-i-have-multiple-colors-in-a-single-textblock-in-wpf](http://stackoverflow.com/questions/2705444/can-i-have-multiple-colors-in-a-single-textblock-in-wpf) – SachiraChin Jan 06 '16 at 02:34 -
1@EmpereurAiman After small research, found way to bind. Please refer this. [http://stackoverflow.com/questions/1959856/data-binding-the-textblock-inlines#9546372](http://stackoverflow.com/questions/1959856/data-binding-the-textblock-inlines#9546372) – SachiraChin Jan 06 '16 at 02:47