Winui3 日期选择器更新日期

问题描述 投票:0回答:1

如何更新日期选择器元素中的日期。我有一个包含日期的 int64_t 属性 m_myDate。

主窗口.xaml.cpp

    ...
    void MainWindow::saveBtn_Click(IInspectable const& sender, Microsoft::UI::Xaml::RoutedEventArgs const& args)
    {
        DateTime dateTime;
        dateTime = myDatePicker().Date();
        m_myDate = dateTime.time_since_epoch().count();
    }

    void MainWindow::loadBtn_Click(IInspectable const& sender, Microsoft::UI::Xaml::RoutedEventArgs const& args)
    {
        DateTime dateTime;
        dateTime.time_since_epoch(std::chrono::nanoseconds(m_myDate)); // replace this with correct code
        myDatePicker().Date(dateTime);
    }
    ...

环境 c++20 winui3

所有文件作为 VS 2022 项目 https://1drv.ms/u/s!AsM8s08DJk30u5kAsOK-A6MOZ8YiSg?e=whhfzN

datepicker c++20 winui-3
1个回答
0
投票
    void MainWindow::saveBtn_Click(IInspectable const& sender, Microsoft::UI::Xaml::RoutedEventArgs const& args)
    {
        DateTime dateTime;
        dateTime = myDatePicker().Date();
        m_myDate = dateTime.time_since_epoch().count();
        myTextBox().Text(to_hstring(m_myDate));
    }

    void MainWindow::loadBtn_Click(IInspectable const& sender, Microsoft::UI::Xaml::RoutedEventArgs const& args)
    {
        myDatePicker().SelectedDate(winrt::Windows::Foundation::DateTime{ winrt::Windows::Foundation::TimeSpan{m_myDate} });
        myDatePicker().UpdateLayout();
    }
© www.soinside.com 2019 - 2024. All rights reserved.