Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1640
Binding.DoNothing overrides current theme
posted

Hi,

I'm setting the forecolor of of a field based on another field of the record using a IValueConverter only under the condition that the ShowColor field of the record is a string that can represents a Color. It goes like this:

<igDP:CellBinding Property="Foreground" Target="CellValuePresenter"
Binding="{Binding Path=DataItem.ShowColor, Converter={StaticResource colorToForeBrushConverter}}"/>

And the ColorToForeBrushConverter goes like this:

public class ColorToForeBrushConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value is Color)
        {
            return new SolidColorBrush((Color)value);
        }
        else if (value is string)
        {
            string ColorString = (string)value;
            if (ColorString == "") //no specified Foreground
            {
                return Binding.DoNothing
            }
            else
            {
                return new SolidColorBrush((Color)(ColorConverter.ConvertFromString(ColorString)));
            }
        }
        return Binding.DoNothing
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {

       var color = new Color();
       if (value is SolidColorBrush)
       {
              color = (value as SolidColorBrush).Color;
       }
       return color;

    }
}

The problem is:

1. Does igDP:CellBinding support conditions?  Meaning to use the ColorToForeBrushConverter only If the DataItem.ShowColor !="".

2. If problem 1 cannot be achieved, ColorToForeBrushConverter returns Binding.DoNothing when DataItem.ShowColor is"" to avoid binding. And this overrides all theme based colors, the Foreground is always Black then. But I don't want it to be black, I want it still be theme specified color, which could vary with themes. How can I achieve this?

Thank you.


Parents Reply Children
No Data