Hi people,
I have problem with RadGridView and background color: I can't set it ! I have a MVVM application and the grid is bind with observable collection; all my data are displayed correctly:
<telerik:RadGridView x:Name="dataGrid" ItemsSource="{Binding Model, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" AutoGenerateColumns="False" FrozenColumnCount="1" CanUserDeleteRows="False" CanUserInsertRows="False" GroupRenderMode="Flat" ShowGroupPanel="False" ClipboardPasteMode="Default" SelectionMode="Extended" SelectionUnit="Cell" ><telerik:GridViewDataColumn Header="Data" DataMemberBinding="{Binding Date}" DataFormatString="{} {0:dd/MM/yyyy}" IsReorderable="False" IsSortable="False" IsFilterable="False" IsReadOnly="True" Width="80" /><telerik:GridViewDataColumn Header="Flow" DataMemberBinding="{Binding Flow}" IsSortable="False" IsFilterable="False" IsReadOnly="True" Width="110" />Now I want to color the row and bind it to property named UserInput (boolean) using converter like this:
internal class UserInputConveter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { var userInput = (bool)value; if (userInput) return new SolidColorBrush(Colors.GreenYellow); return new SolidColorBrush(Colors.Transparent); } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } }But it doesn't work. I tried:
1)
<telerik:RadGridView.RowStyle> <Style TargetType="telerik:GridViewRow"> <Setter Property="Background" Value="{Binding UserInput,Converter={StaticResource UserInputConveter}}"></Setter> </Style></telerik:RadGridView.RowStyle>Result: all my rows disappear!
2)
<telerik:GridViewDataColumn.CellStyle> <Style TargetType="telerik:GridViewCell"> <Setter Property="Background" Value="{Binding Path=UserInput, Converter={StaticResource UserInputConveter}}"></Setter> </Style></telerik:GridViewDataColumn.CellStyle>Result: my single cell disappear.
3)
<telerik:GridViewDataColumn Header="Flow" DataMemberBinding="{Binding Flow}" IsSortable="False" IsFilterable="False" IsReadOnly="True" Width="110" Background="{Binding Path=UserInput, Converter={StaticResource userInputConverter}}" />OR
<telerik:GridViewColumn.Background> <SolidColorBrush Color="{Binding Path=UserInput, Converter={StaticResource userInputConverter}}" /></telerik:GridViewColumn.Background>Result: the color of cell is thedefault, no change.
Where is my error? How I can do it?
Thanks a lot.