C++ 当有一个C++/CX项目中,是否有方法设置CalendarDatePicker的默认日期?

C++ 当有一个C++/CX项目中,是否有方法设置CalendarDatePicker的默认日期?,c++,xaml,uwp,c++-cx,C++,Xaml,Uwp,C++ Cx,我有一个C++/CX UWP项目,希望用户从我使用Windows.UI.Xaml.Controls创建的CalendarDatePicker中选择一个日期。但是,在初始化时,我希望CalendarDatePicker选择一个特定的日期(目前没有选择日期,它只是说“选择一个日期”)。 我知道C很容易实现这一点,我也很确定C++还有一个方法,但是我还没有找到解决的办法。 是否有人知道如何完成此任务?您可以将特定日期传递给日期选择器->日期。完整步骤如下所示。 解释了DateTime在C++/CX中的

我有一个C++/CX UWP项目,希望用户从我使用Windows.UI.Xaml.Controls创建的CalendarDatePicker中选择一个日期。但是,在初始化时,我希望CalendarDatePicker选择一个特定的日期(目前没有选择日期,它只是说“选择一个日期”)。 我知道C很容易实现这一点,我也很确定C++还有一个方法,但是我还没有找到解决的办法。
是否有人知道如何完成此任务?

您可以将特定日期传递给日期选择器->日期。完整步骤如下所示。 解释了DateTime在C++/CX中的相关用法。因此,我们可以通过SYSTEMTIME->FILETIME->ULARGE\u INTEGER->DateTime获得DateTime。首先,我们使用COleDateTime类解析特定的日期字符串(包括ATLComTime.h,然后再进行转换

#include <ATLComTime.h>

//parse date string
COleDateTime coDT;
coDT.ParseDateTime(L"2012-11-10", 0, 0); 

//get system time struct​
SYSTEMTIME st;​
coDT.GetAsSystemTime(st);​
​
//COleDateTime is in local timezone, DateTime is in UTC, so we need to convert​
SYSTEMTIME st_utc;​
TzSpecificLocalTimeToSystemTime(nullptr, &st, &st_utc);​
​
//get filetime struct to get a time format compatible with DateTime​
FILETIME fileTime;​
SystemTimeToFileTime(&st_utc, &ft);​
​
//use _ULARGE_INTEGER to get a int64 to set the DateTime struct to​
_ULARGE_INTEGER ulint = { fileTime.dwLowDateTime, fileTime.dwHighDateTime };​
​
Windows::Foundation::DateTime myDateTime;​
wfdt.UniversalTime = ulint.QuadPart;​

//set date
MyDatePicker->Date = myDateTime;
#包括
//解析日期字符串
coDT;
密码解析日期时间(L“2012-11-10”,0,0);
//获取系统时间结构​
系统时间st;​
代码GetAsSystemTime(st);​
​
//COleDateTime在本地时区,DateTime在UTC,所以我们需要转换​
系统时间标准utc;​
TzSpecificLocalTimeToSystemTime(nullptr、&st和&st_utc);​
​
//获取filetime结构以获取与DateTime兼容的时间格式​
文件时间文件时间;​
SystemTimeToFileTime(&st_utc和&ft);​
​
//使用_ULARGE_INTEGER获取int64以将DateTime结构设置为​
_ULARGE_INTEGER ulint={fileTime.dwLowDateTime,fileTime.dwHighDateTime};​
​
Windows::Foundation::DateTime myDateTime;​
wfdt.UniversalTime=ulint.QuadPart;​
//设定日期
MyDatePicker->Date=myDateTime;

我终于有了更多的时间来调查这个问题

解决此问题的更简单方法是使用以下代码:

Windows::Globalization::Calendar calendar;
Myguidatepicker->Date = calendar.GetDateTime();
你看过这个吗?