RadiantQ WPF Gantt
Conditional Row Colors
Previous Topic  Next Topic 

Conditional Row Colors


Each row in the GanttTable or FlexyTable can be colored differently by binding the color properties of the DataGridRow with some property in your bound data source. This is illustrated in the "ProjectGantt\Appearance\GanttControlTableCustomization\" sample.


Here is how you could do this:


         // Listen to the LoadingRow event.

         this.ganttControl.TemplateApplied += new EventHandler(

                delegate(object sender, EventArgs e)

                {

                    this.ganttControl.GanttTable.LoadingRow += new EventHandler<DataGridRowEventArgs>(GanttTable_LoadingRow);

                }

                );


        // Format the look and feel of the rows based on some property in the bound item (in this case the activity's name).

        void GanttTable_LoadingRow(object sender, DataGridRowEventArgs e)

        {

            DataGridRow row = e.Row;


            // To bind to properties in your bound data source, use this: "Activity.DataSource.SomeProperty"

            Binding binding = new Binding("Activity.ActivityName");

            binding.Converter = new TaskToRowForegroundConverter();


            row.SetBinding(ForegroundProperty, binding);

        }


        // Use this converter to return a brush based on the name of the activity.

#region IValueConverter Members


        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

        {

            string name = (string)value;

            if(name.ToLower().Contains("child"))

                return new SolidColorBrush(Colors.DarkSeaGreen);

            return new SolidColorBrush(Colors.Black);

        }


        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

        {

            throw new NotImplementedException();

        }


        #endregion


Here is the resultant table look and feel:


Table Rows colored differently based on the task's name




� RadiantQ 2009 - 2019. All Rights Reserved.