I made a converter from string to color and back and it works fine when run but on the editor it just throws a "Token is not valid." error and prevents the editor from showing up, really annoying because it prevents me from using the visual editor.
I made the converter for the ColorPicker from extended WPF toolkit.
Here's the converter code:
public class MaddoColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
Color color = Colors.Black;
if (value != null && !string.IsNullOrWhiteSpace(value.ToString()))
{
string c = value.ToString();
var convertedColor = ColorConverter.ConvertFromString(c);
if (convertedColor != null)
{
color = (Color) convertedColor;
}
}
return color;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value != null)
{
Color color = (Color)value;
Debug.WriteLine(color.ToString());
return color.ToString();
}
return string.Empty;
}
}
And here are some relevant snippets from the form xaml:
<Window.Resources>
<wpfCatalog:MaddoColorConverter x:Key="ColorConverter" />
</Window.Resources>
<xctk:ColorPicker Grid.Row="3" Grid.Column="2" SelectedColor="{Binding ColoreTestoRGB, Converter={StaticResource ColorConverter}}"/>