Reputation: 679
are there a way to change a some part of the labels content in C#?
i know you can do that in the xaml but thats just for manualy typing in the text
i want
Resultatfor_nu_Copy.Content = oprofilbox.Text(green) + "/(yellow)" + obredebox.Text(green) + "-(yellow)" + oFælgestr.Text(green);
Upvotes: 0
Views: 512
Reputation: 97656
Create multiple Run
instances, each with its own color, and add them to a TextBlock
's Inlines
collection.
var textBlock = new TextBlock();
textBlock.Inlines.Add(new Run("Green") { Foreground = Brushes.Green });
textBlock.Inlines.Add(new Run("Yellow") { Foreground = Brushes.Yellow });
myLabel.Content = textBlock;
(If you're curious about why the TextBlock
needs to be there, this answer might interest you.)
Upvotes: 3