using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Telerik.Windows.Controls.GridView;
using ConditionalRowBackgroundFormatting;
using System.Collections.ObjectModel;

namespace WpfApplication57
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
            this.RadGridView1.ItemsSource = Person.GetObservableCollectionOfPersons();
            this.RadGridView1.RowLoaded += new EventHandler<Telerik.Windows.Controls.GridView.RowLoadedEventArgs>(RadGridView1_RowLoaded);
        }

        void RadGridView1_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
        {
            if (e.Row is GridViewHeaderRow && e.Row is GridViewNewRow)
                return;

            Binding colorBinding = new Binding("Age");
            colorBinding.Converter = new ValueToColorConverter();

            e.Row.SetBinding(GridViewRow.BackgroundProperty, colorBinding);
        }

        public class Person
        {
            public Person(int age, string firstName, string lastName)
            {
                this.Age = age;
                this.FirstName = firstName;
                this.LastName = lastName;
            }

            public int Age { get; set; }
            public string FirstName { get; set; }
            public string LastName { get; set; }

            public static ObservableCollection<Person> GetObservableCollectionOfPersons()
            {
                var persons = new ObservableCollection<Person>
			              	{
			              		new Person(30, "John", "Smith"),
			              		new Person(29, "Jane", "Smith"),
			              		new Person(13, "Peter", "Smith")
			              	};
                return persons;
            }
        }
    }
}
