简体   繁体   English

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

[英]'SolidBrush' parameter type is not valid for formatting property 'Foreground'. Parameter name: value

I try change color text RickTextBox wpf in invoke method . 我尝试在invoke方法中更改颜色文本RickTextBox wpf。 But i get some trouble . 但是我遇到了麻烦。 My trouble is 我的麻烦是

'SolidBrush' parameter type is not valid for formatting property 'Foreground'. 'SolidBrush'参数类型对于格式化属性'Foreground'无效。 Parameter name: value 参数名称:值

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);

Please help me 请帮我

Thanks ! 谢谢 !

Use the WPF System.Windows.Media.Brushes class instead of System.Drawing.Brushes from WinForms: 使用WPF System.Windows.Media.Brushes类而不是WinForms中的System.Drawing.Brushes

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 WPF 中使用 WinForms ColorDialog 出现错误:“颜色”参数类型对于格式化属性“背景”无效 - Using WinForms ColorDialog in WPF is giving error: 'Color' parameter type is not valid for formatting property 'Background' InvalidArgument =值'3'对于'索引'无效。 参数名称:索引 - InvalidArgument=Value of'3' is not valid for 'index'. parameter name: index InvalidArgument='-1' 的值对 'index' 无效。 参数名称:索引 - InvalidArgument=Value of '-1' is not valid for 'index'. Parameter name: index InvalidArgument=“0”的值对“SelectedIndex”无效。 参数名称:SelectedIndex - InvalidArgument=Value of '0' is not valid for 'SelectedIndex'. Parameter name: SelectedIndex 值不能为空。 参数名称:类型 - Value cannot be null. Parameter name: type InvalidArgument =值'6'对于索引无效。 参数名称:索引 - InvalidArgument=Value of '6' is not valid for index. Parameter name: index 将属性名称作为参数传递 - Pass property name as parameter 指定的参数超出了有效值的范围。参数名称:值 - Specified argument was out of the range of valid values.Parameter name: value System.ArgumentException:“不是有效的默认值参数名称:defaultValue”(NControl) - System.ArgumentException: 'Not a valid default value Parameter name: defaultValue' (NControl) 指定的参数超出了有效值的范围。 参数名称:值 - Specified argument was out of the range of valid values. Parameter name: value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM