C# 更新WPF中的日历控件
目标:C# 更新WPF中的日历控件,c#,wpf,calendar,C#,Wpf,Calendar,目标: 当我选择日期(例如2010-10-22或2015-05-15)时,日历控件将自动更新 问题: 当我应用此代码时: DateTime mtDateTime = DateTime.Now.AddDays(150); -- cdate_left is the name of the calender control in WPF cdate_left.SelectedDate = mtDateTime; 日历控件将不会更新 我该怎么办 日历似乎无法移动到如此遥远的日期 尝试更改所有关联的参
当我选择日期(例如2010-10-22或2015-05-15)时,日历控件将自动更新 问题:
当我应用此代码时:
DateTime mtDateTime = DateTime.Now.AddDays(150);
-- cdate_left is the name of the calender control in WPF
cdate_left.SelectedDate = mtDateTime;
日历控件将不会更新
我该怎么办
日历似乎无法移动到如此遥远的日期 尝试更改所有关联的参数:
DateTime mtDateTime = datetime.now.AddDays(150);
cdate_left.SelectedDate = mtDateTime
DateTime startDate = new DateTime(dt.Year, dt.Month, 1);
cdate_left.DisplayDateStart = startDate ;
cdate_left.DisplayDateEnd = startDate.AddMonths(3);
cdate_left.DisplayDate = mtDateTime;
cdate_left.SelectedDate = mtDateTime;
在代码末尾添加此行:
cdate_left.DisplayDate = cdate_left.SelectedDate ?? DateTime.Now;
这样可以确保显示所选日期所在的月份。您应该同时设置和如下属性
DateTime mtDateTime = DateTime.Now.AddDays(150);
cdate_left.DisplayDate = mtDateTime;
cdate_left.SelectedDate = mtDateTime;
输出:
您是否尝试过减少天数?成功了吗?最终,成功了。为什么对这个答案投反对票?。。这是正确的。。您的日期已选定,但未显示+1.