2013-11-01 49 views
1

我嘗試實施此Color Picker。但我有「ColorToBrushConverter」的問題。 我在哪裏以及如何將他添加到項目中?爲Windows Phone實施自定義顏色選取器

錯誤列表:

錯誤1個未定義的CLR命名空間。 'clr-namespace'URI指的是無法找到的名稱空間'CustomColorsPicker.Converters'。

錯誤2資源「ColorToBrushConverter」無法解析。

回答

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