Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ';SolidBrush&x27;参数类型对格式化属性无效';前景&x27;。参数名称:value_C#_Wpf_Richtextbox_Textrange - Fatal编程技术网

C# ';SolidBrush&x27;参数类型对格式化属性无效';前景&x27;。参数名称:value

C# ';SolidBrush&x27;参数类型对格式化属性无效';前景&x27;。参数名称:value,c#,wpf,richtextbox,textrange,C#,Wpf,Richtextbox,Textrange,我尝试在invoke方法中更改文本框wpf的颜色。但是我遇到了一些麻烦。我的问题是 “SolidBrush”参数类型对于格式化属性“前台”无效。参数名称:值 我的代码 MethodInvoker action = delegate { TextRange textRange = new TextRange(RtTextProcess.Document.ContentStart, RtTextProcess.Document.ContentEnd); if (txtColor =

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

“SolidBrush”参数类型对于格式化属性“前台”无效。参数名称:值

我的代码

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);
请帮帮我


谢谢

使用WPF
System.Windows.Media.brusks
类,而不是WinForms中的
System.Drawing.brusks

// using System.Drawing; --- remove this
using System.Windows.Media;
...

textRange.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Red);