1

我尝试实现这个Color Picker。但我对“ColorToBrushConverter”有疑问。我可以在哪里以及如何将他添加到项目中?

错误列表:

错误 1 ​​未定义的 CLR 命名空间。“clr-namespace” URI 引用了无法找到的命名空间“CustomColorsPicker.Converters”。

错误 2 无法解析资源“ColorToBrushConverter”。

4

1 回答 1

1

我在网站上没有看到,但您可以轻松地自己编写一个。

namespace MyApp.Converters
{
    using System;
    using System.Windows.Data;
    using System.Windows.Media;

    public class ColorToBrushConverter : IValueConverter
    {
       private readonly SolidColorBrush MagentaBrush = new SolidColorBrush(Colors.Magenta);

       public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var color = value as Color;
            if (color != null)
            {
                return new SolidColorBrush(color);
            }
            return MagentaBrush ;
        }

        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
}
于 2013-11-01T21:02:45.760 回答