WPF TextBlock Color for each Character

只谈情不闲聊 提交于 2019-12-03 10:51:27

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:

You can compose colors by adding each color as a new textbook for example:

            TextBlock printTextBlock = new TextBlock();
            printTextBlock.Foreground = Brushes.Red;
            printTextBlock.Text = "This text will colored with red";

            StackPanel.Children.Add(printTextBlock);

The same for the rest of the text.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!