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

Get the visible dates

4 Answers 124 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Kasper Schou
Top achievements
Rank 1
Kasper Schou asked on 08 Apr 2013, 10:31 AM
On the RadCalendar, how do I get the dates that are visible to the user? 

I have tried the DisplayDateChanged event, and it does fire, but I canĀ“t figure out what dates are visible.

Thanks

4 Answers, 1 is accepted

Sort by
0
Vladi
Telerik team
answered on 11 Apr 2013, 01:36 PM
Hello,

In the current version of the control there isn't a built-in feature that could be used in order to get the current visible dates in the Calendar but it is easily achievable. All you need to do is in the code behind drill to the CalendarButtons and then access their CalendarButtonContent.

The next code snippet represents a possible approach in getting all the visible CalendarButtons which represent the dates in the Calendar in a button click event:

private void Button_Click_1(object sender, RoutedEventArgs e)
{
    var calendarButtons = this.Calendar.ChildrenOfType<CalendarButton>().Select(bt => bt.DataContext).OfType<CalendarButtonContent>().Where(content => content.ButtonType == CalendarButtonType.Date || content.ButtonType == CalendarButtonType.TodayDate).ToList();
}

Hope this is helpful.

Greetings,
Vladi
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Joshua Obal
Top achievements
Rank 1
answered on 25 Jul 2014, 01:23 PM
Hi Vladi,

I believe that this functionality has changed since you posted this example last year. In the current version it seems to return a different set of buttons, not just the ones that are visible.  Is there now a better way to get the visible dates?

Thanks,
Josh
0
Joshua Obal
Top achievements
Rank 1
answered on 25 Jul 2014, 02:05 PM
I mostly managed to determine which dates are visible by checking each item in the collection:
if ((!button.IsFromCurrentView) || button.IsInAnotherView)
However, this does not include the greyed-out dates that are part of a previous or future month.  How do I determine all of the visible dates?

Thanks,
Josh
0
Kalin
Telerik team
answered on 29 Jul 2014, 08:46 AM
Hello Joshua,

Thanks for your feedback.

It appears that there this is an issue with Calendar - it is generating an additional empty CalendarButton and this is why you have more buttons in the collection. I have logged that in our internal backlog and it will be considered for fixing in one of the future release versions of the controls. Meanwhile what I can suggest you would be to also check if the content.Text is not null in order to get the correct buttons:

var calendarButtons = this.Cal.ChildrenOfType<CalendarButton>().Select(bt => bt.DataContext).OfType<CalendarButtonContent>().Where(content => content.ButtonType == CalendarButtonType.Date || (content.ButtonType == CalendarButtonType.TodayDate && content.Text != null)).ToList();

Hope this helps. I have also updated your Telerik points for your involvement.

Regards,
Kalin
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
Calendar
Asked by
Kasper Schou
Top achievements
Rank 1
Answers by
Vladi
Telerik team
Joshua Obal
Top achievements
Rank 1
Kalin
Telerik team
Share this question
or