'SolidBrush'参数类型对于格式化属性"前景"无效。参数名称:值



我尝试在Invoke方法中更改颜色文本ricktextbox wpf。但是我遇到了一些麻烦。我的麻烦是

'solidbrush'参数类型对于格式化属性"前景"无效。参数名称:value

我的代码

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 == "rn")
    {
        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);

请帮助我

谢谢!

使用WPF System.Windows.Media.Brushes类而不是winforms的System.Drawing.Brushes

// using System.Drawing; --- remove this
using System.Windows.Media;
...
textRange.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Red);

相关内容

  • 没有找到相关文章

最新更新