RadDateTimePicker background color

3 posts, 1 answers
  1. Andrea
    Andrea avatar
    52 posts
    Member since:
    Oct 2012

    Posted 21 Dec 2015 Link to this post

    Hello,

    I will have a short intro explaining why i need that (maybe you can find an alternative) you may skip and go to the code.

    i have a scenario like the folowing example:

    There is a List of objects, its properties are unknown at compile time (dynamic objects built from database), say these objects only have one property, called ExpireDate.

    The user is presented a list of objects (with their expiredate and maybe other properties).

    The user wants to change the expiredate for many of these objects to a specific date, the program will let the user select all the objects that need to be changed and edit the expiredate value in one shot.

    After the user selected the objects to be changed, the UI will show the user a label and a control for each property:

    in our case the control to handle the datetime will have a gray background and a null value if the selected objects have different ExpireDate, will have a white background when the selected objects have all the same ExpireDate value. This way the user knows, looking at a control, if it is blank because all objects have null value or it is blank cause some objects have different values.

    Said that, after some work, this was the prototype code:

    private void InitializeControlsBackground()
    {
        foreach (var c in panel.Controls.OfType<Control>())
        {
            if(EditorModel.GetProperties().OfType<MultiElement.MultiEditPropertyDescriptor>().Any(a=> a.Name == c.Name))
            {
                Color bg = EditorModel.HasManyValues(c.Name) ? Color.Gray : Color.White;
                c.BackColor = bg;
            }
        }
    }

    the problem is that for some controls the background color changes, but for (example) raddatetimepicker the background color does not change, how can I change the background color for the raddatetimepicker?

     

    Best regards

    Andrea

     

  2. Answer
    Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 22 Dec 2015 Link to this post

    Hi Andrea,

    Thank you for writing.

    RadControls are built on top of Telerik Presentation Framework, employing light-weight visual elements, allowing UI customization and delivering a WPF-like experience. Colors and many other visual settings may be defined also from themes or overridden at run-time. That is why in the case of some of the controls the back color from the control is not transferred onto the visual element and has to be introduced to the elements directly. Here is how to do this for RadDateTimePicker:
    radDateTimePicker1.DateTimePickerElement.TextBoxElement.BackColor = Color.Red;
    radDateTimePicker1.DateTimePickerElement.TextBoxElement.Fill.BackColor = Color.Red;

    If you want to reset these settings, use the following method:
    radDateTimePicker1.DateTimePickerElement.TextBoxElement.ResetValue(RadTextBoxElement.BackColorProperty, ValueResetFlags.Local);
    radDateTimePicker1.DateTimePickerElement.TextBoxElement.Fill.ResetValue(FillPrimitive.BackColorProperty, ValueResetFlags.Local);

    I hope that you find this information useful. Should you have any other questions, do not hesitate to contact us.

    Regards,
    Stefan
    Telerik

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Andrea
    Andrea avatar
    52 posts
    Member since:
    Oct 2012

    Posted 28 Dec 2015 in reply to Stefan Link to this post

    Thank you that's working.

     

    Andrea

Back to Top