我想通过单击Calendar Control中的日期使用MouseLeftButtonDown来引发事件。但是直到我点击这个组件之外它才会被提升。
这是xaml代码:
<Controls:BasicCalendar Grid.Row="0"
x:Name="DemoCalendar"
DisplayDate="{Binding Path=DisplayDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
HighlightedDateText="{Binding HighlightedDateText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Grid.Column="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Margin="0,0,0,0"
DateHighlightBrush="Gold">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonDown">
<cal:ActionMessage MethodName="CalendarSelectDateEvent">
<cal:Parameter Value="{Binding ElementName=DemoCalendar, Path=SelectedDate}" />
</cal:ActionMessage>
</i:EventTrigger>
</i:Interaction.Triggers>
</Controls:BasicCalendar>
以下是点击日历中的某个日期后我要提出的事件:
public void CalendarSelectDateEvent(DateTime selectedDate)
{
this.ActualCalendarEvents = this.CalendarEvents.Where(x => x.Date >= selectedDate).ToList();
var a = this.ActualCalendarEvents;
this.ActualCalendarEvents = null;
NotifyOfPropertyChange(() => ActualCalendarEvents);
this.ActualCalendarEvents = a;
NotifyOfPropertyChange(() => ActualCalendarEvents);
}
当我尝试使用Click事件而不是MouseLeftButtonDown时,Calendar Control自动处理它而不触发CalendarSelectDateEvent。有没有办法解雇这两个事件? (对于Calendar Control选择并突出显示dat,对我来说是CalendarSelectDateEvent)
答案 0 :(得分:0)
我已经明白了。最后真的很容易。 Calendar Control具有SelectedDate属性。我刚刚在后面的代码中将SelectedDate绑定到我的属性SelectedDateChanged,当SelectedDate更改时,我引发了事件CalendarSelectDateEvent。
<Controls:BasicCalendar Grid.Row="0"
x:Name="DemoCalendar"
DisplayDate="{Binding Path=DisplayDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
HighlightedDateText="{Binding HighlightedDateText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Grid.Column="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Margin="0,0,0,0"
SelectedDate="{Binding SelectedDateChanged}"
DateHighlightBrush="Gold">
</Controls:BasicCalendar>
像这样:
public DateTime SelectedDateChanged
{
get
{
return selectedDateChanged;
}
set
{
this.selectedDateChanged = value;
this.CalendarSelectDateEvent(this.selectedDateChanged);
}
}