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

Change date colors in Rad calendar

20 Answers 851 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
shraddha
Top achievements
Rank 2
shraddha asked on 16 Oct 2009, 06:58 AM
Hi,
I am using Telerik WPF control rad calendar.
I want to highlight some dated in that and  want to disable some dates in runtime. Is it possible?

--Thanks
Shraddha

20 Answers, 1 is accepted

Sort by
0
Kaloyan
Telerik team
answered on 20 Oct 2009, 09:23 AM
Hi shraddha,

Consider using the DayTemplateSelector property of the RadCalendar. You can check our RadCalendar first look example, as it is showing these exact feature of the control. Let us know if you need any further assistance.

Best wishes,
Kaloyan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
shraddha
Top achievements
Rank 2
answered on 23 Oct 2009, 07:36 AM
Hi,
Thanx for the help.
I tried using DayTemplateSelector and DataTemplate. And it is working fine.
I have set of special dates which i want to update (add and remove dates from set) in runtime.
How can i achieve that??

---Thanx.
0
Kaloyan
Telerik team
answered on 26 Oct 2009, 11:32 AM
Hi shraddha,

I am not sure if I am understanding correctly your request. Can you please explain deeply what do you mean by 'add and remove dates from set in runtime' as RadCalendar doesn't allow such operations.

All the best,
Kaloyan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
shraddha
Top achievements
Rank 2
answered on 26 Oct 2009, 11:56 AM
Hi,
In the example that you have given, You are selecting some dates (with binding calendar to some CustomdateSelection class). 
Suppose those dates are 12 and 15. I want to change that set of date to 12, 15 and 20 and so on.... Like these can I add and remove dates from the set in the runtime???
Let me know if you need any more clarification.
-- Thanx.
0
Kaloyan
Telerik team
answered on 28 Oct 2009, 01:52 PM
Hello shraddha,

Now I am getting the idea of your request. Unfortunately this is not possible with the current version of the control. We will consider an improvement of the control in this direction for some of the future releases. I hope that this is not a show stopper for your application.

Greetings,
Kaloyan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Vytautas Smitas
Top achievements
Rank 1
answered on 06 Nov 2009, 10:46 AM
Hi shraddha,

I don't know if I understood correctly, but when I want to refresh date coloured on runtime, I just update one List and when call a method which consits of these 3 lines:

DataTemplateSelector dts = radCalendar1.DayTemplateSelector; 
radCalendar1.DayTemplateSelector = new DisableWeekendsSelection(); 
radCalendar1.DayTemplateSelector = dts; 
 My DataTemplateSelector class gets that List and recolours the dates.

Maybe it's not a perfect solution, but it works and it works fast. :)
0
Kaloyan
Telerik team
answered on 12 Nov 2009, 08:33 AM
Hi Vytautas Smitas,

This is a possible solution. The only problem is that you need  to create a couple of different DayTemplateSelector based classes. We will think of some improvements of the RadCalendar on those  aspects.

Regards,
Kaloyan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Viren
Top achievements
Rank 1
answered on 27 Sep 2010, 08:55 PM
Hi Everyone,

I am facing a similar problem. I have like a list of dates that I need to highlight in the calendar. I fetched the list form sql server in the backend and store it in an array of DateTime type in my C# code behind. Its a WPF application. Now I want to keep  today's (current) date highlighted as it is, but also want to highlight this list of dates that I am fetching in the radcalendar. I tried adding the list to the SelectedDates property of the radcalendar but it that messes up my OnSelectionChanged event handler. Any solution as to how to highlight a few dates on the  calendar?

Thanks
0
Kaloyan
Telerik team
answered on 30 Sep 2010, 02:40 PM
Hi Viren,

You have to use the DayTemplateSelector or DayTemplate property. There you can define the appearance of each calendar item in a class that implements the aforementioned classes . Find the referred example with the exact implementation.

Sincerely yours,
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
Viren
Top achievements
Rank 1
answered on 30 Sep 2010, 09:32 PM
Thank you Kaloyan. I will try to implement this and will get back whenever I get a chance.
0
Gabriel
Top achievements
Rank 1
answered on 12 Nov 2010, 11:15 AM
Hi,
Maybe this will help you guys:

The purpose of these attached properties are to select a template for special days (like for example bold the days of the month that have  appointments or color holidays from a database). MVVM friendly.

In the viewmdodel we have:
private List<DateTime> _datesWithAppointments;
        public List<DateTime> DatesWithAppointments
        {
            get
            {
                return _datesWithAppointments;
            }
            set
            {
                if (_datesWithAppointments != value)
                {
                    _datesWithAppointments = value;
                    NotifyPropertyChanged("DatesWithAppointments");
                }
            }
        }


We populate these dates:
DatesWithAppointments = Appointments.Select(x => x.Start.Date).ToList();


in xaml we have the datatemplate for special days:
<DataTemplate x:Key="SpecialDayTemplate">
            <TextBlock Text="{Binding Text}" FontWeight="Bold" />
</DataTemplate>


and the RadCalendar is defined in xaml:
<telerik:RadCalendar Margin="0,10,0,0" x:Name="radCalendar" VerticalAlignment="Top" DisplayDate="{Binding MySelectedDate}" SelectedDate="{Binding MySelectedDate, Mode=TwoWay}" telerik:StyleManager.Theme="Office_Blue" local:RadCalendarBehavior.SpecialDayTemplate="{StaticResource SpecialDayTemplate}" local:RadCalendarBehavior.SpecialDays="{Binding DatesWithAppointments}" />


The final pieces of the puzzle are the custom daytemplateselector and the attached properties:
public class SpecialDaySelector : DataTemplateSelector
    {
        private List<DateTime> _specialDates;
        private DataTemplate _specialDayTemplate { get; set; }
 
        public SpecialDaySelector(List<DateTime> specialDates, DataTemplate specialDayTemplate)
        {
            _specialDates = specialDates;
            _specialDayTemplate = specialDayTemplate;
        }
 
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            var content = item as CalendarButtonContent;
            if (content != null)
            {
                if (_specialDates.Contains(content.Date))
                {
                    return _specialDayTemplate;
                }
            }
            return base.SelectTemplate(item, container);
        }
    }
 
    public class RadCalendarBehavior : DependencyObject
    {
        private static void OnSpecialDaysChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var calendar = d as RadCalendar;
            if (e.NewValue != null)
            {
                calendar.DayTemplateSelector = new SpecialDaySelector((List<DateTime>)e.NewValue, GetSpecialDayTemplate(d));
            }
        }
 
        public static List<DateTime> GetSpecialDays(DependencyObject obj)
        {
            return (List<DateTime>)obj.GetValue(SpecialDaysProperty);
        }
 
        public static void SetSpecialDays(DependencyObject obj, List<DateTime> value)
        {
            obj.SetValue(SpecialDaysProperty, value);
        }
 
        public static readonly DependencyProperty SpecialDaysProperty =
            DependencyProperty.RegisterAttached("SpecialDays", typeof(List<DateTime>), typeof(RadCalendarBehavior), new UIPropertyMetadata(null, OnSpecialDaysChanged));
 
        public static DataTemplate GetSpecialDayTemplate(DependencyObject obj)
        {
            return (DataTemplate)obj.GetValue(SpecialDayTemplateProperty);
        }
 
        public static void SetSpecialDayTemplate(DependencyObject obj, DataTemplate value)
        {
            obj.SetValue(SpecialDayTemplateProperty, value);
        }
 
        public static readonly DependencyProperty SpecialDayTemplateProperty =
            DependencyProperty.RegisterAttached("SpecialDayTemplate", typeof(DataTemplate), typeof(RadCalendarBehavior), new UIPropertyMetadata(null));
    }

Hope it helps.
0
Kaloyan
Telerik team
answered on 16 Nov 2010, 09:11 AM
Hello Gabriel,

You can find a similar approach in our FirstLook demo example. And your workaround is acceptable too.

Best wishes,
Kaloyan
the Telerik team
See What's New in RadControls for WPF in Q3 2010 on Tuesday, November 16, 2010 11:00 AM - 12:00 PM EST or 10:00 PM - 11:00 PM EST: Register here>>
0
David
Top achievements
Rank 1
answered on 03 Dec 2010, 02:05 AM
Hi Gabriel,

Thanks for posting a MVVM solution.

It would be good if Telerik updated their examples for MVVM. It's so frustrating when they use a StaticResource in their examples, when what you really need is an example that allows you bind to your ViewModel.

Dave
0
Kaloyan
Telerik team
answered on 07 Dec 2010, 01:16 PM
Hello David,

Thank you for the note. We will take the suggestion into account for the next update of the calendar examples.

Regards,
Kaloyan
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
0
alexander rodriguez
Top achievements
Rank 1
answered on 24 Dec 2010, 08:11 PM
hi shraddha,

Can you share me your DataTemplateSelector class. Thanks
0
Kshamesh
Top achievements
Rank 1
answered on 09 Aug 2012, 03:48 PM
Hello Gabriel,

You solution is very perfect in my requirement. I would like to understand if i can select different data templates based on custom logic instead of returning SpecialDayTemplate each time. I have GreenDayTemplate, RedDayTemplate etc. To process this custom logic I have custom dateTime collection property.

Your help in this regard would be much appreciated!

Regards,
Kshamesh
0
Adrian
Top achievements
Rank 2
answered on 11 Nov 2013, 08:30 PM
Telerik: 
Have you guys incorporated an easier method to altering special dates as mentioned previously in this post or is the same approach still the recommendation?
0
Konstantina
Telerik team
answered on 14 Nov 2013, 03:19 PM
Hello,

We haven't changed the way of altering the special dates. You will have to use DayTemplateSelector or DayTemplate property as suggested in one of the previous posts.

Regards,
Konstantina
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Lerner
Top achievements
Rank 1
answered on 15 Aug 2014, 03:28 PM
Hello Gabriel

Thanks for your solution, i try'd to implement it but i have a little problem that the special date are not shown when the window is loaded only after i change the view to year and go back or if i go t a different month and come back than it shows, so if you can help it should show up when the calender loads the first time.
 
Thanks .
0
Lerner
Top achievements
Rank 1
answered on 15 Aug 2014, 03:32 PM
Hello Vytautas Smitas

Thanks for your solution can you please explain me more how this works, what is the DisableWeekendsSelection?

Thanks.
Tags
Calendar
Asked by
shraddha
Top achievements
Rank 2
Answers by
Kaloyan
Telerik team
shraddha
Top achievements
Rank 2
Vytautas Smitas
Top achievements
Rank 1
Viren
Top achievements
Rank 1
Gabriel
Top achievements
Rank 1
David
Top achievements
Rank 1
alexander rodriguez
Top achievements
Rank 1
Kshamesh
Top achievements
Rank 1
Adrian
Top achievements
Rank 2
Konstantina
Telerik team
Lerner
Top achievements
Rank 1
Share this question
or