Set back color to week days.

4 posts, 1 answers
  1. Freddy
    Freddy avatar
    25 posts
    Member since:
    Feb 2013

    Posted 14 Jul 2013 Link to this post

    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
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 14 Jul 2013 Link to this post

    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.
  3. DevCraft banner
  4. Freddy
    Freddy avatar
    25 posts
    Member since:
    Feb 2013

    Posted 15 Jul 2013 Link to this post

    Thanks, I have another requirement to set a custom color on hovering dates in the calendar. So please help me to get it.
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 15 Jul 2013 Link to this post

    Hi Freddy,

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

    Thanks,
    Shinu.
Back to Top