how to get each character of a textblock of different color in wpf?
1 Answer
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:
-
2
-
-
1@EmpereurAiman You can't bind
List<Run>
toText
property ofTextBlock
. But you can bind toText
value of individualRun
. Try: http://stackoverflow.com/questions/2705444/can-i-have-multiple-colors-in-a-single-textblock-in-wpf Jan 6, 2016 at 2:34 -
1@EmpereurAiman After small research, found way to bind. Please refer this. http://stackoverflow.com/questions/1959856/data-binding-the-textblock-inlines#9546372 Jan 6, 2016 at 2:47