[英]c# wpf - Right-Click to change SelectedDate and show ContextMenu
I want to implement rightclick event in RadCalendar to change the SelectedDates and also showing the ContextMenu at the same time. 我想在RadCalendar中实现rightclick事件,以更改SelectedDates并同时显示ContextMenu。 I'm using this code :
我正在使用此代码:
<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>
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;
}
}
}
If i remove the comment in radCalendar.SelectedDate = calendarButtonContent.Date;
如果我删除
radCalendar.SelectedDate = calendarButtonContent.Date;
中的注释radCalendar.SelectedDate = calendarButtonContent.Date;
i can select the dates by rightclick, but i need to rightclick again to show the ContextMenu, if i keep it in comment i ContextMenu will show up but i can't change the SelectedDates with rightclick. 我可以通过右键单击选择日期,但是我需要再次右键单击以显示ContextMenu,如果我将其保留在注释中,则将显示ContextMenu,但我无法通过右键单击来更改SelectedDates。
Solved 解决了
instead of using Opened i used Opening and add the handled property 而不是使用Opened我使用了Opening并添加了handle属性
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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.