This question is locked. New answers and comments are not allowed.
I have a GridView where for certain the values are Nullable Booleans, when the value happens to be null, the controls renders a CheckBox with the IsTrueState property to true, presenting a CheckBox with a minus sign on it, something I feel is quite unnoticeable, so I decided to color the cell with a background color but only when the condition of being null is met. the problem is that the binding seems to be ignored by the control
I have the following code: For the Value Converter.
I have the following code: For the Value Converter.
public class TriStateBooleanToStyleValueConverter : IValueConverter
{
public object Convert(object value,
Type targetType,
object parameter,
System.Globalization.CultureInfo culture)
{
ResourceDictionary converterDictionary = new ResourceDictionary()
{
Source = new Uri("/SilverlightApplication1;component/Assets/Styles.xaml", UriKind.RelativeOrAbsolute)
};
if (value == null)
{
return converterDictionary["NullCellRedStyle"] as Style;
}
else
{
return converterDictionary["NullCellWhiteStyle"] as Style;
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
For the Styles defined in Styles.xaml<Style x:Key="NullCellRedStyle" TargetType="telerik:GridViewCell">Also have the Converter defined as a resource in the same styles file
<Setter Property="Background" Value="#FFFFD8D8"/>
</Style>
<Style x:Key="NullCellWhiteStyle" TargetType="telerik:GridViewCell">
<Setter Property="Background" Value="#FFFFFFFF"/>
</Style>
<converters:TriStateBooleanToStyleValueConverter x:Key="TriBoolToStyle"/>At the column level I have the following:
<telerik:GridViewDataColumn Header="To Pay" MinWidth="70" Width="90" DataMemberBinding="{Binding Path=ToPay}" CellStyle="{Binding Path=ToPay, Converter={StaticResource TriBoolToStyle}}" />I define the CellStyle directly without binding and it works, also, I placed a breakpoint into the converter and it is never reached.
Thanks
Juan Mejia