C# 更改textblock中部分文本的颜色
我需要为部分文本字符串更改代码中的颜色 我举个例子:C# 更改textblock中部分文本的颜色,c#,wpf,string,colors,code-behind,C#,Wpf,String,Colors,Code Behind,我需要为部分文本字符串更改代码中的颜色 我举个例子: textblock1.Text = string1 + string2 + string3; 字符串具有动态值,我希望在以蓝色运行程序后显示string2,并且它必须在代码中定义 有可能吗?谢谢大家! 我希望这将对您有所帮助: <TextBlock FontSize="16"> <Run Foreground="Red">Your_Text_1</Run> <Run
textblock1.Text = string1 + string2 + string3;
字符串具有动态值,我希望在以蓝色运行程序后显示string2,并且它必须在代码中定义
有可能吗?谢谢大家! 我希望这将对您有所帮助:
<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>
你的文字
你的文字
你的文字
那是工作吗
textblock1.Inlines.Clear();
textblock1.Inlines.Add(new Run(string1));
textblock1.Inlines.Add(new Run(string2) { Foreground = Brushes.Blue });
你可以用“跑”
例如:“运行Name=“Value\u from\u codebeahind”/>”
在代码隐藏中附加值谢谢您的回复,但我需要在代码隐藏中定义它,因为textblock不显示静态文本,但不同数量的变量具有不同的值:/请参考以下答案: