This is a migrated thread and some comments may be shown as answers.

RadGridView Binding Backgound Colors etc Not working

4 Answers 10 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
stevea
Top achievements
Rank 1
stevea asked on 14 May 2014, 02:48 PM

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





























4 Answers, 1 is accepted

Sort by
0
stevea
Top achievements
Rank 1
answered on 14 May 2014, 02:49 PM
Controls are version 2014.1.331.1050
0
Dimitrina
Telerik team
answered on 16 May 2014, 03:02 PM
Hello,

I tested the code snippet and as it turns out the Converter is only called initially. The Background is not reevaluated as I am changing the value of the IsValid property at runtime. 

May I ask you what is the final result you would like to achieve? Why do you need to set the Background with Binding?

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
stevea
Top achievements
Rank 1
answered on 21 May 2014, 06:39 PM
The background needs to be set with a binding, because when a value changes, the cell color must change.
0
Yoan
Telerik team
answered on 26 May 2014, 09:12 AM
Hello,

In this case, you can work with CellStyleSelector as demonstrated in this online demo. Please check the 
CellStyleSelector help article for a reference.

Regards,
Yoan
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
General Discussions
Asked by
stevea
Top achievements
Rank 1
Answers by
stevea
Top achievements
Rank 1
Dimitrina
Telerik team
Yoan
Telerik team
Share this question
or