I have an application where I am trying to do some custom validation. I run some semi-complex rules and update a property IsValid which I bind to a background property of a GridViewDataColumn.
I bind the grid Datasource in a code behind to a QueryableCollectionView based on an Observable collection of "MyModel" , all columns bind correctly.
If I manually set the background color in Xaml, to Red obviously it turns red. The binding I show below does not work
Background="{Binding Path=IsValid, Converter={StaticResource cc}}" > and Background="{Binding IsValid, Converter={StaticResource cc}}" >.
Some sample source
Grid Xaml
01.
<
telerik:RadGridView
telerik:StyleManager.Theme
=
"Office_Blue"
x:Name
=
"RadGridView1"
02.
Grid.Row
=
"1"
03.
GroupRenderMode
=
"Flat"
04.
ShowGroupPanel
=
"False"
05.
Height
=
"500"
06.
Width
=
"1000"
07.
ColumnWidth
=
"*"
08.
AutoGenerateColumns
=
"False"
09.
HorizontalAlignment
=
"Center"
10.
VerticalAlignment
=
"Top"
11.
CanUserFreezeColumns
=
"False"
12.
RowIndicatorVisibility
=
"Collapsed"
13.
ItemsSource
=
"{Binding }"
14.
NewRowPosition
=
"Top"
15.
AddingNewDataItem
=
"RadGridView1_AddingNewDataItem"
16.
RowEditEnded
=
"RadGridView1_RowEditEnded"
>
17.
<
telerik:RadGridView.Resources
>
18.
<
Converters:ColorConverter
x:Key
=
"cc"
/>
19.
</
telerik:RadGridView.Resources
>
.... More grid Code
Column Xaml
1.
<
telerik:GridViewDataColumn
Header
=
"MyColumn"
2.
DataMemberBinding
=
"{Binding Inventory.ChrStart, Mode=TwoWay}"
3.
Width
=
"*"
4.
Background
=
"{Binding Path=IsValid, Converter={StaticResource cc}}"
>
5.
</
telerik:GridViewDataColumn
>
Converter Code:
01.
public class ColorConverter : IValueConverter
02.
{
03.
public object Convert(object value,
04.
Type targetType,
05.
object parameter,
06.
CultureInfo culture)
07.
{
08.
bool cellIsValid = ((int)value==0?false:true);
09.
if (!cellIsValid)
10.
{
11.
return new SolidColorBrush(Colors.Red);
12.
}
13.
else
14.
{
15.
return new SolidColorBrush(Colors.Transparent);
16.
}
17.
}
18.
19.
public object ConvertBack(object value,
20.
Type targetType,
21.
object parameter,
22.
CultureInfo culture)
23.
{
24.
throw new NotImplementedException();
25.
// return new SolidColorBrush(Colors.Red);
26.
}
27.
}
Model class
01.
public class MyModel : INotifyPropertyChanged
02.
{
03.
int _isvalid;
04.
public int IsValid
05.
{
06.
get
07.
{
08.
return _isvalid;
09.
}
10.
set
11.
{
12.
if (_isvalid != value)
13.
{
14.
_isvalid = value;
15.
OnPropertyChanged("IsValid");
16.
}
17.
}
18. ... Other properties etc
19.
}
20.
21.
}
gdgdfg