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

Silverlight Calendar DayTemplateSelector

4 Answers 79 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Burbank
Top achievements
Rank 1
Burbank asked on 24 Nov 2011, 03:52 AM
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);
            }
        }

    }

4 Answers, 1 is accepted

Sort by
0
Ivo
Telerik team
answered on 28 Nov 2011, 02:37 PM
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 >>

0
Burbank
Top achievements
Rank 1
answered on 30 Nov 2011, 12:14 AM
Thank you Ivo. The explanation and the code sample are very helpful.
0
Anup
Top achievements
Rank 2
answered on 10 May 2013, 11:59 AM
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
0
Ventzi
Telerik team
answered on 14 May 2013, 08:34 AM
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.

Tags
Calendar
Asked by
Burbank
Top achievements
Rank 1
Answers by
Ivo
Telerik team
Burbank
Top achievements
Rank 1
Anup
Top achievements
Rank 2
Ventzi
Telerik team
Share this question
or