Calendar not updating correctly visually when overriding DayTemplateSelector

3 posts, 0 answers
  1. Jose
    Jose avatar
    2 posts
    Member since:
    Dec 2014

    Posted 02 Dec 2014 Link to this post

    This is similar to the following post:

    I took the sample provided by the Telerik help on that thread and reproduced the issue

    Step 1
    Create a simple DayTemplateSelector:
    public class DateTemplateSelector : DataTemplateSelector
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
            return base.SelectTemplate(item, container);

    Step 2
    Wire up the xaml (omitted non-relevant code):
        <dateTimePickerSl:DateTemplateSelector x:Key="DateTemplateSelector"/>
    <Grid x:Name="LayoutRoot" Background="White">
        <telerik:RadDatePicker x:Name="datePickerEndDate" Grid.Row="2" >
                <Style TargetType="telerik:RadCalendar">
                    <Setter Property="DayTemplateSelector" Value="{StaticResource DateTemplateSelector}"/>

    Step 3
    Run app and click bring down down calendar.

    Result-October.png doesn't have October 31st. Also noticed how the October 29th and October 30th are showed as disabled (part of the next month)
    Result-Semptember.png shows the same days except some are disabled and some are not (which is incorrect). Also, notice the week numbers on left hand side doesn't update. These week numbers are from the month of December. If you keep going back on the calendar, the week numbers will not be updated either.

    Has this issue been fixed and/or is there a workaround?

  2. Kalin
    Kalin avatar
    1352 posts

    Posted 03 Dec 2014 Link to this post

    Hello Jose,

    The reason for the observed behavior is that the base.SelecteTemplate method returns null. In scenarios like this one you would need to implement a DefaultTemplate that will be returned instead of calling the base method. So the DateTemplateSelector should look as shown below:

    public class DateTemplateSelector : DataTemplateSelector
        public DataTemplate DefaultTemplate { get; set; }
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
            return this.DefaultTemplate;

    And the XAML:

    <local:DateTemplateSelector x:Key="DateTemplateSelector">
                <TextBlock Text="{Binding Text}" />

    Hope this helps.


    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

  3. Jose
    Jose avatar
    2 posts
    Member since:
    Dec 2014

    Posted 09 Dec 2014 in reply to Kalin Link to this post

    Thanks Kalin!

    It worked like a charm. It drove me crazy for a couple of days because I think this was working on a previous version of Telerik. It doesn't matter. I hope others find this answer helpful.
Back to Top