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

ContextMenu on RadCalendar and RadScheduleView

3 Answers 207 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Aldy
Top achievements
Rank 1
Aldy asked on 29 Sep 2015, 08:35 AM
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.

3 Answers, 1 is accepted

Sort by
0
Aldy
Top achievements
Rank 1
answered on 29 Sep 2015, 09:13 AM
do i need to use a custom DataTemplateSelector?
0
Nasko
Telerik team
answered on 01 Oct 2015, 01:41 PM
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
0
Aldy
Top achievements
Rank 1
answered on 02 Oct 2015, 08:18 AM

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 :)

 

Tags
ContextMenu
Asked by
Aldy
Top achievements
Rank 1
Answers by
Aldy
Top achievements
Rank 1
Nasko
Telerik team
Share this question
or