如何更新日期选择器元素中的日期。我有一个包含日期的 int64_t 属性 m_myDate。
TimeSpan
是 std::chrono::duration
的专业化。DateTime
std::chrono::time_point
的专业化。MainWindow.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
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();
}