Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > Calendar > Refresh calendar (reselecting datatemplate)

Answered Refresh calendar (reselecting datatemplate)

Feed from this thread
  • Kasper Schou avatar

    Posted on Apr 8, 2011 (permalink)

    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

    Reply

  • Kasper Schou avatar

    Posted on Apr 8, 2011 (permalink)

    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

    Reply

  • Answer Kaloyan Kaloyan admin's avatar

    Posted on Apr 14, 2011 (permalink)

    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

    Reply

  • Kasper Schou avatar

    Posted on Apr 14, 2011 (permalink)

    Hi Kaloyan,

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

    Best regards,
    Kasper Schou

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > Calendar > Refresh calendar (reselecting datatemplate)
Related resources for "Refresh calendar (reselecting datatemplate)"

WPF Calendar Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]