c# wpf - 右键单击​​以更改 SelectedDate 并显示 ContextMenu

c# wpf - Right-Click to change SelectedDate and show ContextMenu

我想在 RadCalendar 中实现右键单击事件以更改 SelectedDates 并同时显示 ContextMenu。我正在使用此代码:

XAML

<telerik:RadCalendar Name="radCalendar"
                     Canvas.Left="80"
                     Canvas.Top="200"
                     Height="320"
                     Width="400"
                     SelectedDate="{Binding CurrentDate, ElementName=radScheduleView, Mode=TwoWay}"
                     SelectionMode="Single"
                     DisplayDate="{Binding DisplayDate, Mode=TwoWay}">
    <telerik:RadContextMenu.ContextMenu>
        <telerik:RadContextMenu Opened="RadContextMenu_Opened">
            <telerik:RadMenuItem x:Name="expandOverview"
                                 Header="Expand Overview"
                                 Click="expandOverview_Click" />
            <telerik:RadMenuItem x:Name="showLayouts"
                                 Header="Show Layouts"
                                 Click="showLayouts_Click" />
        </telerik:RadContextMenu>
    </telerik:RadContextMenu.ContextMenu>
</telerik:RadCalendar>

CS

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;
            //radCalendar.SelectedDate = calendarButtonContent.Date;
        }
    }
}

如果我删除 radCalendar.SelectedDate = calendarButtonContent.Date; 中的评论,我可以通过右键单击 select 日期,但我需要再次右键单击以显示上下文菜单,如果我将其保留在评论中,我将显示上下文菜单但我无法通过右键单击更改 SelectedDates。

已解决

我没有使用 Opened,而是使用了 Opening 并添加了已处理的 属性

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;
            radCalendar.SelectedDate = calendarButtonContent.Date;
        }
    }
    else
    {
        e.Handled = true;
    }
}