Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change color in part of text in textblock

I need change color in code behind for part of text string..

My exaple:

textblock1.Text = string1 + string2 + string3;

String have dynamic values, and i want to string2 display after running the program in blue color and it must be defined in the code behind.

Its possible? Thank you!

like image 487
Honza Kalina Avatar asked Nov 13 '14 10:11

Honza Kalina


People also ask

Which of the following is used to change the color of the form?

Detailed Solution The correct answer is Font color.

What is TextBlock in XAML?

TextBlock is the primary control for displaying read-only text in apps. You can use it to display single-line or multi-line text, inline hyperlinks, and text with formatting like bold, italic, or underlined.


2 Answers

That working

                        textblock1.Inlines.Clear();
                        textblock1.Inlines.Add(new Run(string1));
                        textblock1.Inlines.Add(new Run(string2) { Foreground = Brushes.Blue });
like image 196
Honza Kalina Avatar answered Sep 18 '22 10:09

Honza Kalina


I Hope that will help you:

<TextBlock FontSize="16">
        <Run Foreground="Red">Your_Text_1</Run>
        <Run Foreground="Orange">Your_Text_2</Run>
        <Run Foreground="purple">Your_Text_3</Run>
</TextBlock>
like image 23
Dotnetter Avatar answered Sep 21 '22 10:09

Dotnetter