Get the visible dates

5 posts, 0 answers
  1. Kasper Schou
    Kasper Schou avatar
    21 posts
    Member since:
    Jul 2009

    Posted 08 Apr 2013 Link to this post

    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
  2. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 11 Apr 2013 Link to this post

    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.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Joshua Obal
    Joshua Obal avatar
    2 posts
    Member since:
    Jul 2006

    Posted 25 Jul 2014 in reply to Vladi Link to this post

    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
  5. Joshua Obal
    Joshua Obal avatar
    2 posts
    Member since:
    Jul 2006

    Posted 25 Jul 2014 in reply to Joshua Obal Link to this post

    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
  6. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 29 Jul 2014 Link to this post

    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.
     
Back to Top
UI for WPF is Visual Studio 2017 Ready