RadGridView Binding Backgound Colors etc Not working

5 posts, 0 answers
  1. stevea
    stevea avatar
    9 posts
    Member since:
    Apr 2007

    Posted 14 May 2014 Link to this post


    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





























  2. stevea
    stevea avatar
    9 posts
    Member since:
    Apr 2007

    Posted 14 May 2014 Link to this post

    Controls are version 2014.1.331.1050
  3. DevCraft banner
  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 16 May 2014 Link to this post

    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.
     
  5. stevea
    stevea avatar
    9 posts
    Member since:
    Apr 2007

    Posted 21 May 2014 in reply to Dimitrina Link to this post

    The background needs to be set with a binding, because when a value changes, the cell color must change.
  6. Yoan
    Admin
    Yoan avatar
    1070 posts

    Posted 26 May 2014 Link to this post

    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.
     
Back to Top
DevCraft banner