首页 > 解决方案 > 如何在 UWP C++/WinRT 项目中使用 CalendarDatePicker::Date() 属性?

问题描述

我希望用户从返回 Windows::Foundation::IReference 的 CalendarDatePicker 中选择一个Date() 。但是我调用Windows::Foundation::IReference::GetDateTime()将能够引发异常。

输出消息:

在 BlankApp1.exe 中的 0x00007FFDC893A839 (KernelBase.dll) 处引发异常:WinRT 发起错误 - 0x80004001:“未实现”。

在 BlankApp1.exe 中的 0x00007FFDC893A839 处引发异常:Microsoft C++ 异常:winrt::hresult_not_implemented 在内存位置 0x00000071C2DFCB18。

在 BlankApp1.exe 中的 0x00007FFDC893A839 处引发异常:Microsoft C++ 异常:[rethrow] 在内存位置 0x0000000000000000。

BlankApp1.exe 已触发断点。

引发异常的代码:

Windows::Foundation::IReference<Windows::Foundation::DateTime> date = MyCalendar().Date();
    if (date != nullptr) {
        auto dt = date.GetDateTime();
    }
    else {
        OutputDebugStringA("You not pick a date.");
    }

App.cpp的UnhandledException中的应用分解:

App::App() {
    InitializeComponent();
    Suspending({ this, &App::OnSuspending });

#if defined _DEBUG && !defined DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
    UnhandledException([this](IInspectable const&, UnhandledExceptionEventArgs const& e) {
        if (IsDebuggerPresent()) {
            auto errorMessage = e.Message();
            __debugbreak();
        }
    });
#endif
}

errorMessage 的值为“未实现”。

有人知道如何获取日期吗?

标签: c++uwpc++-winrt

解决方案


推荐阅读