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

Set back color to week days.

3 Answers 26 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Freddy
Top achievements
Rank 1
Freddy asked on 14 Jul 2013, 08:43 AM
Hello

I am using RadControls in my silverlight application and there is a radcalendar. I would like to display all sundays in a separate color. I tried giving few styles but didnt worked. So please help me with this.

Freddy

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 1
answered on 14 Jul 2013, 10:34 AM
Hi Freddy,

This can be achieved by creating a custom StyleSelector and setting it to the DayButtonStyleSelector property of the control. The custom DayButtonStyleSelector that inherits StyleSelector class can be created as follows.

C#:
public class DayButtonStyleSelector : StyleSelector
{
    public Style SpecialStyleSunday { get; set; }
 
    public override Style SelectStyle(object item, DependencyObject container)
    {
        CalendarButtonContent content = item as CalendarButtonContent;
        if (content != null)
        {
            if (content.Date.DayOfWeek == DayOfWeek.Sunday && content.ButtonType == CalendarButtonType.Date)
            {
                return SpecialStyleSunday;
            }
        }
        return base.SelectStyle(item, container);
    }
}

Next add the namespace in the XAML.

XAML:
<UserControl x:Class="CalendarDayButtonStyle.MainPage"
             ...
             xmlns:local="clr-namespace:CalendarDayButtonStyle"
             xmlns:calendar="clr-namespace:Telerik.Windows.Controls.Calendar;assembly=Telerik.Windows.Controls.Input"
             ...>
</UserControl>

Create a StaticResource for the DayButtonStyleSelector and the SpecialStyleSunday Style.

XAML:
<local:DayButtonStyleSelector x:Key="CustomStyleSelector">
    <local:DayButtonStyleSelector.SpecialStyleSunday>
        <Style TargetType="calendar:CalendarButton">
            <Setter Property="Background">
                <Setter.Value>
                    <SolidColorBrush Color="Red" Opacity="0.5"/>
                </Setter.Value>
            </Setter>
        </Style>
    </local:DayButtonStyleSelector.SpecialStyleSunday>
</local:DayButtonStyleSelector>

Finally set the DayButtonStyleSelector property of the control and set the DayButtonStyle to null in order for the custom DayButtonStyleSelector to be used as follows.

XAML:
<telerik:RadCalendar DayButtonStyleSelector="{StaticResource CustomStyleSelector}"
                     DayButtonStyle="{x:Null}"/>

Thanks,
Shinu.
0
Freddy
Top achievements
Rank 1
answered on 15 Jul 2013, 09:06 AM
Thanks, I have another requirement to set a custom color on hovering dates in the calendar. So please help me to get it.
0
Shinu
Top achievements
Rank 1
answered on 15 Jul 2013, 10:24 AM
Hi Freddy,

Please download this sample project which deals with changing the mouse over color of the RadCalendar.

Thanks,
Shinu.
Tags
Calendar
Asked by
Freddy
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Freddy
Top achievements
Rank 1
Share this question
or