我有一个WPF RichTextBox,我试图做的是改变风格: FontFamily,FontSize,FontWeight,Color等等。
我可以在选定的文本上更改其中一些值,但找不到TextDecorationProperty
CodeExample:
TextSelection textRange = richTextBoxWpf.Selection;
if (btBold.IsChecked ?? false)
{
textRange.ApplyPropertyValue(FontWeightProperty, FontWeights.Bold);
btBold.IsChecked = true;
}
else
{
btBold.IsChecked = false;
textRange.ApplyPropertyValue(FontWeightProperty, FontWeights.Normal);
}我的代码在设置属性时失败:
var pens = new System.Windows.Media.Pen(System.Windows.Media.Brushes.Black, 1);
textRange.ApplyPropertyValue(TextDecoration.PenProperty, pens);失败错误-消息:“模笔-Eigenschaft ist für die Textformatierung nicht gültig.”
发布于 2022-09-14 08:55:38
抱歉,经过长时间的搜索,我自己找到了解决办法:
它在Documents.Inline类中:
TextSelection textRange = richTextBoxWpf.Selection;
textRange.ApplyPropertyValue(Inline.TextDecorationsProperty, TextDecorations.Underline);https://stackoverflow.com/questions/73713981
复制相似问题