Silverlight Calendar DayTemplateSelector

5 posts, 0 answers
  1. Burbank
    Burbank avatar
    3 posts
    Member since:
    Nov 2009

    Posted 23 Nov 2011 Link to this post

    I am trying to use the DayTemplateSelector to Select special days on the Calendar but I am having problems because I am getting my data (dates) from Ria Service. The Asynchronous nature of obtaining data makes it difficult to get the dates for SelectTemplate method . Any help on this will be highly appreciated. Below is part of the code:

     public class CustomDayTemplateSelector : DataTemplateSelector
        {
            private WarrantyContext _Context = null;
            private List<Inspection> _Inpections;

            public CustomDayTemplateSelector()
            {
                _Context = new WarrantyContext();
                _Inpections = new List<Inspection>();
                LoadOperation<Inspection> loadOp = _Context.Load(_Context.GetInspectionsQuery());
                loadOp.Completed += new EventHandler(LoadAppointments_Completed);
            }

            public override DataTemplate SelectTemplate(object item, DependencyObject container)
            {
                CalendarButtonContent content = item as CalendarButtonContent;

                foreach (var a in _Inpections)
                {
                    if (a.StartDate == content.Date)
                    {
                        return this.ActivityTemplate;
                    }
                }

                return DefaultTemplate;
            }

            public DataTemplate DefaultTemplate { get; set; }
            public DataTemplate ActivityTemplate { get; set; }    

            private void LoadAppointments_Completed(object sender, EventArgs e)
            {
                foreach (var inspection in _Context.Inspections)
                {
                    Inspection appointment = new Inspection();
                    appointment.StartDate = inspection.StartDate;
                    appointment.EndDate = inspection.EndDate;
                    appointment.UserId = inspection.UserId;
                    _Inpections.Add(appointment);
                }
            }

        }
  2. Ivo
    Admin
    Ivo avatar
    390 posts

    Posted 28 Nov 2011 Link to this post

    Hi Burbank,

    This can be achieved by reseting the template when your appointments are loaded. You can find an example attached. Into the example SpecialEvent is added on button click and the RadCalendar template is reset.

    All the best,
    Ivo
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Burbank
    Burbank avatar
    3 posts
    Member since:
    Nov 2009

    Posted 29 Nov 2011 Link to this post

    Thank you Ivo. The explanation and the code sample are very helpful.
  5. Anup
    Anup avatar
    13 posts
    Member since:
    Aug 2011

    Posted 10 May 2013 Link to this post

    Hello Sir,

    Will you please have me your appreciated response i am with the code..

    i have review the code its fantastic but i have used with DataTemplate override method...
    where its not working even though the Date selected on the calendar the DisplayDateSelectionChanged not fired out...
    please refer the below links too i am urgent to have the solution...
    http://www.telerik.com/community/forums/silverlight/calendar/daytemplateselector-calendar-not-working.aspx

    please have me your kind attention here 

    Thank you,
    Anup Shah
  6. Ventzi
    Admin
    Ventzi avatar
    114 posts

    Posted 14 May 2013 Link to this post

    Hi Anup,

    We've already answered your question in this thread. We would like kindly ask you to continue our conversation there.

    All the best,
    Ventzi
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
DevCraft banner