C# ';SolidBrush&x27;参数类型对格式化属性无效';前景&x27;。参数名称:value
我尝试在invoke方法中更改文本框wpf的颜色。但是我遇到了一些麻烦。我的问题是 “SolidBrush”参数类型对于格式化属性“前台”无效。参数名称:值 我的代码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 =
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);