簡體   English   中英

'SolidBrush'參數類型對於格式化屬性'Foreground'無效。 參數名稱:值

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

我嘗試在invoke方法中更改顏色文本RickTextBox wpf。 但是我遇到了麻煩。 我的麻煩是

'SolidBrush'參數類型對於格式化屬性'Foreground'無效。 參數名稱:值

我的密碼

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.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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM