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

Calendar not updating correctly visually when overriding DayTemplateSelector

2 Answers 130 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Jose
Top achievements
Rank 1
Jose asked on 02 Dec 2014, 06:35 PM
This is similar to the following post:
http://www.telerik.com/forums/date-picker-date-day-are-not-matching-after-replacing-2014-dlls

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):
<UserControl.Resources>
    <dateTimePickerSl:DateTemplateSelector x:Key="DateTemplateSelector"/>
</UserControl.Resources>
 
<Grid x:Name="LayoutRoot" Background="White">
    <telerik:RadDatePicker x:Name="datePickerEndDate" Grid.Row="2" >
        <telerik:RadDatePicker.CalendarStyle>
            <Style TargetType="telerik:RadCalendar">
                <Setter Property="DayTemplateSelector" Value="{StaticResource DateTemplateSelector}"/>
            </Style>
        </telerik:RadDatePicker.CalendarStyle>
    </telerik:RadDatePicker>
</Grid>

Step 3
Run app and click bring down down calendar.

Result:
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?

Thanks,
Jose

2 Answers, 1 is accepted

Sort by
0
Kalin
Telerik team
answered on 03 Dec 2014, 01:44 PM
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">
    <local:DateTemplateSelector.DefaultTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Text}" />
        </DataTemplate>
    </local:DateTemplateSelector.DefaultTemplate>
</local:DateTemplateSelector>

Hope this helps.

Regards,
Kalin
Telerik
 

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.

 
0
Jose
Top achievements
Rank 1
answered on 09 Dec 2014, 06:49 PM
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.
Tags
DatePicker
Asked by
Jose
Top achievements
Rank 1
Answers by
Kalin
Telerik team
Jose
Top achievements
Rank 1
Share this question
or