Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 更新WPF中的日历控件_C#_Wpf_Calendar - Fatal编程技术网

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.