From fd48f6ec1d6655988b97a2891930399c1d0b7c6f Mon Sep 17 00:00:00 2001 From: Quentin <27322516+quentin987@users.noreply.github.com> Date: Wed, 6 May 2020 17:14:54 -0500 Subject: [PATCH] Switching from Difference between dates to Add or subtract dates ignores the first date field (#1210) --- src/Calculator/Views/DateCalculator.xaml.cpp | 22 +++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Calculator/Views/DateCalculator.xaml.cpp b/src/Calculator/Views/DateCalculator.xaml.cpp index 9fc0084b..f18293d8 100644 --- a/src/Calculator/Views/DateCalculator.xaml.cpp +++ b/src/Calculator/Views/DateCalculator.xaml.cpp @@ -186,7 +186,27 @@ void DateCalculator::SetDefaultFocus() void DateCalculator::DateCalcOption_Changed(_In_ Platform::Object ^ sender, _In_ Windows::UI::Xaml::Controls::SelectionChangedEventArgs ^ e) { FindName("AddSubtractDateGrid"); - DateCalculationOption->SelectionChanged -= m_dateCalcOptionChangedEventToken; + auto dateCalcViewModel = safe_cast(this->DataContext); + + // From Date Field needs to persist across Date Difference and Add Substract Date Mode. + // So when the mode dropdown changes, update the other datepicker with the latest date. + if (dateCalcViewModel->IsDateDiffMode) + { + if (AddSubtract_FromDate->Date == nullptr) + { + return; + } + DateDiff_FromDate->Date = AddSubtract_FromDate->Date->Value; + } + else + { + if (DateDiff_FromDate->Date == nullptr) + { + // If no date has been picked, then this can be null. + return; + } + AddSubtract_FromDate->Date = DateDiff_FromDate->Date->Value; + } } void CalculatorApp::DateCalculator::AddSubtractDateGrid_Loaded(_In_ Platform::Object ^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs ^ e)