【发布时间】:2016-04-10 11:05:25
【问题描述】:
有没有办法在 C# 中更改部分标签内容?
我知道你可以在 xaml 中做到这一点,但这只是为了手动输入文本
我想要
Resultatfor_nu_Copy.Content = oprofilbox.Text(green) + "/(yellow)" + obredebox.Text(green) + "-(yellow)" + oFælgestr.Text(green);
【问题讨论】:
有没有办法在 C# 中更改部分标签内容?
我知道你可以在 xaml 中做到这一点,但这只是为了手动输入文本
我想要
Resultatfor_nu_Copy.Content = oprofilbox.Text(green) + "/(yellow)" + obredebox.Text(green) + "-(yellow)" + oFælgestr.Text(green);
【问题讨论】:
创建多个Run 实例,每个实例都有自己的颜色,并将它们添加到TextBlock 的Inlines 集合中。
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;
(如果您对TextBlock 需要存在的原因感到好奇,this answer 可能会让您感兴趣。)
【讨论】: