如何检测日历 BlackoutDates 上的 MouseDoubleClick?
How to detect MouseDoubleClick on Calendar BlackoutDates?
在我的 WPF/C# 应用程序中,我有一个 Calendar
控件,范围设置为 BlackoutDates
。我也想处理 MouseDoubleClick
事件,但我看不到如何确定用户是否双击了中断日期 - 在这种情况下返回给事件处理程序的日期是最近选择的有效日期(即非停电日期)日期。我如何 "ignore" 双击这些 BlackoutDates
?
编辑:
XAML:
<Calendar MouseDoubleClick="Calendar_MouseDoubleClick"/>
后面的代码:
private void Calendar_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if (myCalendarBlackoutDatesCollection.Contains(/* what goes here? */))
{
return; // ignore doubleclick
}
// execution continues here
}
您可以通过定义 CalendarDayButtonStyle
:
来处理每个人 CalendarDayButton
的 MouseDoubleClick
<Calendar x:Name="cal">
<Calendar.CalendarDayButtonStyle>
<Style TargetType="CalendarDayButton">
<EventSetter Event="MouseDoubleClick" Handler="cal_MouseDoubleClick" />
</Style>
</Calendar.CalendarDayButtonStyle>
</Calendar>
private void cal_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
System.Windows.Controls.Primitives.CalendarDayButton button = sender as System.Windows.Controls.Primitives.CalendarDayButton;
DateTime clickedDate = (DateTime)button.DataContext;
if (!cal.BlackoutDates.Contains(clickedDate))
{
MessageBox.Show("No blackout date was clicked!");
}
}
在我的 WPF/C# 应用程序中,我有一个 Calendar
控件,范围设置为 BlackoutDates
。我也想处理 MouseDoubleClick
事件,但我看不到如何确定用户是否双击了中断日期 - 在这种情况下返回给事件处理程序的日期是最近选择的有效日期(即非停电日期)日期。我如何 "ignore" 双击这些 BlackoutDates
?
编辑:
XAML:
<Calendar MouseDoubleClick="Calendar_MouseDoubleClick"/>
后面的代码:
private void Calendar_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if (myCalendarBlackoutDatesCollection.Contains(/* what goes here? */))
{
return; // ignore doubleclick
}
// execution continues here
}
您可以通过定义 CalendarDayButtonStyle
:
CalendarDayButton
的 MouseDoubleClick
<Calendar x:Name="cal">
<Calendar.CalendarDayButtonStyle>
<Style TargetType="CalendarDayButton">
<EventSetter Event="MouseDoubleClick" Handler="cal_MouseDoubleClick" />
</Style>
</Calendar.CalendarDayButtonStyle>
</Calendar>
private void cal_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
System.Windows.Controls.Primitives.CalendarDayButton button = sender as System.Windows.Controls.Primitives.CalendarDayButton;
DateTime clickedDate = (DateTime)button.DataContext;
if (!cal.BlackoutDates.Contains(clickedDate))
{
MessageBox.Show("No blackout date was clicked!");
}
}