How to set the different EventContainer background color

2 posts, 0 answers
  1. zhu
    zhu avatar
    3 posts
    Member since:
    Apr 2019

    Posted 23 Apr 2019 Link to this post

    Hi guys,

    I Want to change the EventContainer background color by Progress Value

    please tell me how to set How to set the different EventContainer background color

  2. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    1179 posts

    Posted 25 Apr 2019 Link to this post

    Hi zhu,

    You can set a different Background for the different tasks based on their Progress by defining a similar style:

    <local:ProgressToBackgroundBrushConverter x:Key="ProgressToBackgroundBrushConverter" />
    <Style TargetType="telerik:EventContainer">
        <Setter Property="Background" Value="{Binding OriginalEvent.Progress, Converter={StaticResource ProgressToBackgroundBrushConverter}}" />
    </Style>

    In the converter you can then determine what brushes to return based on the current progress:

    public class ProgressToBackgroundBrushConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var progress = double.Parse(value.ToString());
            if (progress < 20)
            {
                return Brushes.Red;
            }
     
            return Brushes.Green;
        }
     
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    I've prepared a small sample project to demonstrate this in action.

    Please have a look and let me know if such an approach would work for you.

    Regards,
    Dilyan Traykov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top