ContextMenu on RadCalendar and RadScheduleView

4 posts, 0 answers
  1. Aldy
    Aldy avatar
    8 posts
    Member since:
    Sep 2015

    Posted 29 Sep 2015 Link to this post

    I want to use ContextMenu on the dates in RadCalendar so i can pick the dates and show ContextMenu using right-click, there is an issue that makes me able to right-click on header and somewhere else(but still in Calendar) and the ContextMenu also showed up. this is the code
    <telerik:RadCalendar x:Name="calendar">
            <telerik:RadContextMenu.ContextMenu>
                <telerik:RadContextMenu Opened="RadContextMenu_Opened">
                    <telerik:RadMenuItem Header="Copy" />
                    <telerik:RadMenuItem Header="Paste" />
                    <telerik:RadMenuItem Header="Cut" />
                </telerik:RadContextMenu>
            </telerik:RadContextMenu.ContextMenu>
        </telerik:RadCalendar>

     

    private void RadContextMenu_Opened(object sender, RoutedEventArgs e)
        {
            var calendarButton = (sender as RadContextMenu).GetClickedElement<CalendarButton>();
            if (calendarButton != null)
            {
                var calendarButtonContent = calendarButton.Content as CalendarButtonContent;
                if (calendarButtonContent != null)
                {
                    var clickedDate = calendarButtonContent.Date;
     
                }
            }
        }

    i also want to do that on RadScheduleView so i can only use the ContextMenu on the empty slots or appointment.

  2. Aldy
    Aldy avatar
    8 posts
    Member since:
    Sep 2015

    Posted 29 Sep 2015 Link to this post

    do i need to use a custom DataTemplateSelector?
  3. UI for WPF is Visual Studio 2017 Ready
  4. Nasko
    Admin
    Nasko avatar
    587 posts

    Posted 01 Oct 2015 Link to this post

    Hi Aldy,

    In order to achieve the desired behavior of RadContextMenu you need to handle the Opening event. Inside it you need to check if the clicked UIElement is a CalendarButton and if its ButtonType is either a Date or TodayDate. If one of these conditions is not valid the Handled property should be set to True and thus the ContextMenu wont'be visualized:
    private void RadContextMenu_Opening(object sender, Telerik.Windows.RadRoutedEventArgs e)
    {
        var calendarButton = (sender as RadContextMenu).GetClickedElement<CalendarButton>();
        if (calendarButton != null && (calendarButton.ButtonType == CalendarButtonType.Date || calendarButton.ButtonType == CalendarButtonType.TodayDate))
        {
            var calendarButtonContent = calendarButton.Content as CalendarButtonContent;
            if (calendarButtonContent != null)
            {
                var clickedDate = calendarButtonContent.Date;
     
            }
        }
        else
        {
            e.Handled = true;
        }
    }

    The exact same approach could be used for RadScheduleView either.

    Hope this helps.

    Regards,
    Nasko
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  5. Aldy
    Aldy avatar
    8 posts
    Member since:
    Sep 2015

    Posted 02 Oct 2015 in reply to Nasko Link to this post

    Hi Nasko,

    wow thank you so much!

    and now i can also change the SelectedDates while opening the ContextMenu by using

    radCalendar.SelectedDate = calendarButtonContent.Date;
    thank you so much :)

     

Back to Top