我尝试在调用方法中更改颜色文本 RichTextBox wpf 。但我遇到了一些麻烦。我的麻烦是
“SolidBrush”参数类型对于格式化属性“Foreground”无效。参数名称:值
My code
MethodInvoker action = delegate
{
TextRange textRange = new TextRange(RtTextProcess.Document.ContentStart, RtTextProcess.Document.ContentEnd);
if (txtColor == null) txtColor = Color.Black;
int start = textRange.Text.Length;
var txt = string.Concat(DateTime.Now.ToString(), " : ", text);
if (textRange.Text == "\r\n")
{
textRange.Text = "";
}
else
{
textRange.Text += txt.ToString();
}
TextPointer start1 = textRange.Start.GetPositionAtOffset(start, LogicalDirection.Forward);
TextPointer end = textRange.Start.GetPositionAtOffset(txt.Length, LogicalDirection.Backward);
if (start1 != null && end != null)
{
RtTextProcess.Selection.Select(start1, end);
}
// My error is here
textRange.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Red);
string rtb = RtTextProcess.Selection.Text;
};
RtTextProcess.Dispatcher.Invoke(action);
请帮我
Thanks !
使用WPFSystem.Windows.Media.Brushes
类而不是System.Drawing.Brushes
来自 WinForms:
// using System.Drawing; --- remove this
using System.Windows.Media;
...
textRange.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Red);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)