我希望日历控件只显示月份和十年,因为不需要这一天。启动时,日历控件的日期设置为今天的日期。这就是我所拥有的:
XAML:
<Calendar SelectedDate="{Binding FromMonthYear}" Name="FromCalendar" DisplayMode="{Binding CalendarDisplayMode}" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="DisplayModeChanged" >
<i:InvokeCommandAction Command="{Binding OnCalendarDisplayModeCommand}"
CommandParameter="{Binding ElementName=FromCalendar, Path=DisplayMode}" />
</i:EventTrigger>
<i:EventTrigger EventName="DisplayDateChanged" >
<i:InvokeCommandAction Command="{Binding OnCalendarDisplayDateCommand}"
CommandParameter="{Binding ElementName=FromCalendar, Path=SelectedDate}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Calendar>
<Button Content="Run Report" Name="RunReportButton"
Command="{Binding OnRunReportCommand}" />
C#:
private DateTime _fromMonthYear;
public DateTime FromMonthYear
{
get { return _fromMonthYear; }
set { Set(() => FromMonthYear, ref _fromMonthYear, value); }
}
private void OnRunReportPress()
{
var d = FromMonthYear;
}
private void OnCalendarDisplayModeChange()
{
CalendarDisplayMode = CalendarMode.Year;
Mouse.Capture(null);
}
private void OnCalendarDisplayDateChange(object date)
{
var d = FromMonthYear;
}
我有两个问题。第一种是当显示模式设置为一年时,点击日历中的年份不会显示几十年,但左右箭头会切换年份。第二个问题是,当OnReportReportPress和OnCalendarDisplayDateChange方法执行时,FromMonthYear属性不会更新。如何解决这两个问题?感谢