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

Refresh calendar (reselecting datatemplate)

5 Answers 410 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Kasper Schou
Top achievements
Rank 1
Kasper Schou asked on 08 Apr 2011, 11:40 AM
Hi Telerik,

I'm having trouble getting the calendar to reselect template for the calendarbuttoncontent after initial load.

I've found that if I "browse" the calendar (so that the content is not shown) and back again, the template is reapplied, using updated information in my behind lists of dates.

I have created the following template selector:

public class CalendarButtonTemplateSelector : DataTemplateSelector
{
    public override DataTemplate SelectTemplate(object item, DependencyObject container)
    {
        CalendarButtonContent content = item as CalendarButtonContent;
        if (content != null && content.ButtonType == CalendarButtonType.Date)
        {
            if (CentralCalendarWindow.CalendarViewItems != null && CentralCalendarWindow.CalendarViewItems.Exists(c => c.Date == content.Date))
            {
                CalendarViewItem calendarViewItem = CentralCalendarWindow.CalendarViewItems.Find(c => c.Date == content.Date);
                if (calendarViewItem.Holiday)
                {
                    return HolidayTemplate;
                }
                else if (calendarViewItem.NoDistribution)
                {
                    return NoDistributionTemplate;
                }
                else if (calendarViewItem.PartlyNoDistribution)
                {
                    return PartlyNoDistributionTemplate;           
                }
            }
        }
        return DefaultTemplate;
    }
    public DataTemplate DefaultTemplate { get; set; }
    public DataTemplate HolidayTemplate { get; set; }
    public DataTemplate NoDistributionTemplate { get; set; }
    public DataTemplate PartlyNoDistributionTemplate { get; set; }
}

In XAML i bind to the selector as a static resource like this:

DayTemplateSelector="{StaticResource templateSelector}"

And my template selection is like this:

<this:CalendarButtonTemplateSelector x:Key="templateSelector"
      DefaultTemplate="{StaticResource dataTemplateDefault}"
      HolidayTemplate="{StaticResource dataTemplateHoliday}"
      NoDistributionTemplate="{StaticResource dataTemplateNoDistribution}"
      PartlyNoDistributionTemplate="{StaticResource dataTemplatePartlyNoDistribution}"/>


Now the question - How can I explicitly have the calendar redo its template selection, like it does when the content gets redrawn when "browsing" the calendar.

And what I would really want to do is to only redo the template selection on specific days if possible.

Thanks in advance!
Best regards,
Kasper Schou

5 Answers, 1 is accepted

Sort by
0
Kasper Schou
Top achievements
Rank 1
answered on 08 Apr 2011, 12:19 PM
Just to clarify, the following code will reapply the template selection:

DateTime current = _calendar.DisplayDate;
_calendar.DisplayDate = current.AddYears(1);
_calendar.DisplayDate = current;

But obviously I'm not very fond of using the above in my solution :)

/Kasper
0
Accepted
Kaloyan
Telerik team
answered on 14 Apr 2011, 09:37 AM
Hi Kasper Schou,

Sorry for the late response. What you can do is as follows:

var currentSelector = calendar.DayTemplateSelector;
calendar.DayTemplateSelector = null;
calendar.DayTemplateSelector = currentSelector;


Kind regards,
Kaloyan
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Kasper Schou
Top achievements
Rank 1
answered on 14 Apr 2011, 01:39 PM
Hi Kaloyan,

Thank you for the reply, this is somewhat more pretty and works just fine :)

Best regards,
Kasper Schou
0
Andrew
Top achievements
Rank 1
answered on 26 Oct 2012, 06:37 PM
I've tried doing this by resetting the DayTemplateSelector as suggested and it works to an extent, but I have found that, although though the day templates are recalculated, the day buttons become disabled until I manually change months. Changing the DisplayDate as Kasper once mentioned works and doesn't cause this issue. Do you have any suggestions on how to fix this problem? 
0
Konstantina
Telerik team
answered on 31 Oct 2012, 03:50 PM
Hi,

I think this is the best approach for now. Hope it is acceptable for you.
If you need further information please let us know.

Regards,
Konstantina
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
Calendar
Asked by
Kasper Schou
Top achievements
Rank 1
Answers by
Kasper Schou
Top achievements
Rank 1
Kaloyan
Telerik team
Andrew
Top achievements
Rank 1
Konstantina
Telerik team
Share this question
or