Possible Duplicate:
Can I have multiple colors in a single TextBlock in WPF?
是否可以对 WPF TextBlock 的各个部分进行样式设置,例如将某个单词设置为粗体、斜体或下划线?您可以更改所有字体属性吗?如果是这样,什么解决方案是最漂亮且最有效的性能?
最佳答案
您可以在 XAML 中的 TextBlock 中单独设置运行样式,也可以使用 Inlines
.cs 代码隐藏文件中的属性。 This blog post表示您至少可以设置字体样式、字体粗细、前景色和字体大小的样式。
XAML:
<TextBlock>
<Run Text="SomeText" FontWeight="Bold" FontStyle="Italic"/>
<Run Text=" some more text" FontSize="12"/>
<Run Text=" and more" Foreground="Blue"/>
</TextBlock >
这是一个示例,显示从 C# Corner 添加画笔到运行中:
<Run.Foreground>
<LinearGradientBrush>
<GradientStop Color="Green" Offset="0.0" />
<GradientStop Color="Purple" Offset="0.25" />
<GradientStop Color="Orange" Offset="0.5" />
<GradientStop Color="Blue" Offset="0.75" />
</LinearGradientBrush>
</Run.Foreground>
您可以通过编程方式访问的 Inlines
集合是 System.Windows.Documents.Run
的集合。对象。
关于c# - 您可以设置 WPF TextBlock 的各个部分的样式吗?如果可以,如何设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12222416/