This is a migrated thread and some comments may be shown as answers.

Style Certain Dates

1 Answer 40 Views
Calendar, DateTimePicker, TimePicker and Clock
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 26 May 2011, 09:39 PM
I'm using Q1 2011.

I simply want to change the style of a specific set of dates that are determined at runtime.

I'm overriding the ElementRender event and setting properties like e.Element.Font, e.Element.ForeColor, etc. This works great. For instance:

private void calSchedule_ElementRender(object sender, RenderElementEventArgs e)
{
    if(myDates.Contains(e.Day.Date))
    {
        e.Element.Font = new Font(e.Element.Font.FontFamily, 9f, FontStyle.Bold);
        e.Element.ForeColor = Color.Green;
        e.Element.AutoToolTip = true;
    }
}


The problem is, from that point on, the cell will continue to render those styles even if the date inside that cell changes. (Like when the calender's month is change.)

Since the "correct" style for the cell can vary, I can't simply reset the values manually. How can I resolve this?

1 Answer, 1 is accepted

Sort by
0
Ivan Todorov
Telerik team
answered on 28 May 2011, 12:31 PM
Hello Robert,

Thank you for your question.

In RadCalendar the visual elements are reused when possible and that is why when you create a local property setting, it remains when the date in cell has changed. You can reset the properties which are RadProperties by using the ResetValue method which will set a RadProperty with its default or theme value:
private void calSchedule_ElementRender(object sender, RenderElementEventArgs e)
{
    if(myDates.Contains(e.Day.Date))
    {
        e.Element.Font = new Font(e.Element.Font.FontFamily, 9f, FontStyle.Bold);
        e.Element.ForeColor = Color.Green;
        e.Element.AutoToolTip = true;
    }
    else
    {
         e.Element.ResetValue(VisualElement.FontProperty);
         e.Element.ResetValue(VisualElement.ForeColorProperty);
         e.Element.AutoToolTip = false;
    }
}

I hope this will help you. Feel free to ask if you have any additional questions.

Greetings,
Ivan Todorov
the Telerik team
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
Tags
Calendar, DateTimePicker, TimePicker and Clock
Asked by
Robert
Top achievements
Rank 1
Answers by
Ivan Todorov
Telerik team
Share this question
or