![](/img/trans.png)
[英]Using WinForms ColorDialog in WPF is giving error: 'Color' parameter type is not valid for formatting property 'Background'
[英]'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.