Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > Calendar > Setting SelectedDates

Answered Setting SelectedDates

Feed from this thread
  • Toby avatar

    Posted on Jun 3, 2010 (permalink)

    Hi,
    Hopefully a quick question:
    With the calendar control there is a SelectedDate property which allows me to get/set a date to be highlighted/selected. However i need to highlight/select a daterange from code. There is a selectedDates property, which allows you to get a List<DateTime> of selected dates, however i need to set this. Is there a way to do this?
    Many thanks,

    Reply

  • Rick Glos avatar

    Posted on Jun 3, 2010 (permalink)

    I'm interested in the answer to this as well.  According to the documentation, this is bindable - see here.

    Although it is exposed as a list, you can bind it and... 

    But when attempting to use it you get an error.

    'SelectedDates' property is read-only and cannot be set from markup.  

    Or if you try and set in code you get an error.

                // Property or indexer 'Telerik.Windows.Controls.RadCalendar.SelectedDates' cannot be assigned to -- it is read only 
                radCalendar1.SelectedDates = new List<DateTime>(); 


    Reply

  • Toby avatar

    Posted on Jun 4, 2010 (permalink)

    Your link to the documentation got me thinking. I tried the following as a work around:
    private void setDate(DateTime from, DateTime to) 
            { 
                //clear selection 
                dateRangeCalendar.SelectedDate = null
                //loop through range 
                DateTime dateToAdd = from; 
                while (dateToAdd <= to) 
                { 
                    //add to selection 
                    dateRangeCalendar.SelectedDates.Add(dateToAdd); 
                    dateToAdd = dateToAdd.AddDays(1); 
                } 
            } 

    It would be helpful to be able to directly bind to a list, or set the list directly, however this should achieve the same thing.


    Reply

  • Rick Glos avatar

    Posted on Jun 4, 2010 (permalink)

    Interesting, I didn't think to use the methods hanging off the IList.  This would certainly give us a work-around.  Although like you, I was hoping to bind this directly to my ViewModel.  It would involve a bit of code hanging off the event handlers on the control to keep this list updated in both directions.

    Telerik, can you tell us was this an oversight, making this property ReadOnly or done purposely?  It would help us determine a course of action.

    Reply

  • Answer Kaloyan Kaloyan admin's avatar

    Posted on Jun 8, 2010 (permalink)

    Hello Rick Glos,

    As you have noticed the property has a readonly accessor. You need to use the Add() method in order to add dates. We will consider adding an ItemsSource property that can be used with MVVM pattern.

    Best wishes,
    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

  • Robert avatar

    Posted on Jan 18, 2011 (permalink)

    Hello Everybody,
    Any news about ItemsSource property in RadCalendar ?

    Reply

  • Kaloyan Kaloyan admin's avatar

    Posted on Jan 21, 2011 (permalink)

    Hello Toby,

    There is no such a property exposed by the RadCalendar yet. You can create an attached property that will add a new selected date into the calendar itself and use it as a binding target. Let us know if you need any further explanation.

    Kind regards,
    Kaloyan
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > Calendar > Setting SelectedDates
Related resources for "Setting SelectedDates"

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