From 31ee0eb6594b3054e8cfa5e98b6ee66d3b0b6c64 Mon Sep 17 00:00:00 2001 From: Stephanie Anderl <46726333+sanderl@users.noreply.github.com> Date: Mon, 4 Mar 2019 10:46:01 -0800 Subject: [PATCH] Reverted textblock callback changes and added an event handler for when the radio buttons are checked. --- src/Calculator/Views/DateCalculator.xaml | 9 ++++++- src/Calculator/Views/DateCalculator.xaml.cpp | 27 +++++++++++++++----- src/Calculator/Views/DateCalculator.xaml.h | 6 ++++- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/Calculator/Views/DateCalculator.xaml b/src/Calculator/Views/DateCalculator.xaml index 5eb4e58b..bcf2cae3 100644 --- a/src/Calculator/Views/DateCalculator.xaml +++ b/src/Calculator/Views/DateCalculator.xaml @@ -1,7 +1,6 @@ @@ -444,6 +444,7 @@ Style="{StaticResource DateCalculation_CalendarPickerStyle}" AutomationProperties.LabeledBy="{x:Bind Date_ToLabel}" CalendarViewStyle="{StaticResource DateCalculation_CalendarViewStyle}" + Closed="CalendarFlyoutClosed" DateChanged="ToDate_DateChanged"/> @@ -501,6 +502,7 @@ Style="{StaticResource DateCalculation_CalendarPickerStyle}" AutomationProperties.LabeledBy="{x:Bind AddSubtract_Date_FromLabel}" CalendarViewStyle="{StaticResource DateCalculation_CalendarViewStyle}" + Closed="CalendarFlyoutClosed" DateChanged="AddSubtract_DateChanged"/> @@ -514,6 +516,7 @@ MinWidth="80" MaxWidth="160" VerticalAlignment="Top" + Checked="AddSubtractOption_Checked" IsChecked="{Binding IsAddMode, Mode=TwoWay}"/> @@ -549,6 +553,7 @@ Grid.Row="1" MinWidth="84" AutomationProperties.LabeledBy="{Binding ElementName=YearsLabel}" + DropDownClosed="OffsetDropDownClosed" ItemsSource="{Binding OffsetValues, Mode=OneTime}" SelectedIndex="{Binding YearsOffset, Mode=TwoWay}" SelectionChanged="OffsetValue_Changed"/> @@ -564,6 +569,7 @@ MinWidth="84" Margin="12,0,12,0" AutomationProperties.LabeledBy="{Binding ElementName=MonthsLabel}" + DropDownClosed="OffsetDropDownClosed" ItemsSource="{Binding OffsetValues, Mode=OneTime}" SelectedIndex="{Binding MonthsOffset, Mode=TwoWay}" SelectionChanged="OffsetValue_Changed"/> @@ -578,6 +584,7 @@ Grid.Column="2" MinWidth="84" AutomationProperties.LabeledBy="{Binding ElementName=DaysLabel}" + DropDownClosed="OffsetDropDownClosed" ItemsSource="{Binding OffsetValues, Mode=OneTime}" SelectedIndex="{Binding DaysOffset, Mode=TwoWay}" SelectionChanged="OffsetValue_Changed"/> diff --git a/src/Calculator/Views/DateCalculator.xaml.cpp b/src/Calculator/Views/DateCalculator.xaml.cpp index 2e6ff459..6c19b3ca 100644 --- a/src/Calculator/Views/DateCalculator.xaml.cpp +++ b/src/Calculator/Views/DateCalculator.xaml.cpp @@ -182,10 +182,6 @@ void DateCalculator::DateCalcOption_Changed(_In_ Platform::Object^ sender, _In_ { FindName("AddSubtractDateGrid"); DateCalculationOption->SelectionChanged -= m_dateCalcOptionChangedEventToken; - - DateResultLabel->RegisterPropertyChangedCallback(TextBlock::TextProperty, ref new DependencyPropertyChangedCallback(this, &DateCalculator::OnDateResultLabelChanged)); - DateDiffAllUnitsResultLabel->RegisterPropertyChangedCallback(TextBlock::TextProperty, ref new DependencyPropertyChangedCallback(this, &DateCalculator::OnDateResultLabelChanged)); - } void CalculatorApp::DateCalculator::AddSubtractDateGrid_Loaded(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs^ e) @@ -211,8 +207,25 @@ void DateCalculator::ReselectCalendarDate(_In_ Windows::UI::Xaml::Controls::Cale calendarDatePicker->IsCalendarOpen = false; } -void DateCalculator::OnDateResultLabelChanged(Windows::UI::Xaml::DependencyObject^ sender, Windows::UI::Xaml::DependencyProperty^ dp) +void DateCalculator::OffsetDropDownClosed(_In_ Object^ sender, _In_ Object^ e) { - String^ automationName = AutomationProperties::GetName(sender); - TextBlockAutomationPeer::FromElement((TextBlock^)sender)->RaiseAutomationEvent(AutomationEvents::LiveRegionChanged); + RaiseLiveRegionChangedAutomationEvent(false); +} + +void DateCalculator::CalendarFlyoutClosed(_In_ Object^ sender, _In_ Object^ e) +{ + auto dateCalcViewModel = safe_cast(this->DataContext); + RaiseLiveRegionChangedAutomationEvent(dateCalcViewModel->IsDateDiffMode); +} + +void DateCalculator::RaiseLiveRegionChangedAutomationEvent(_In_ bool isDateDiffMode) +{ + TextBlock^ resultTextBlock = (isDateDiffMode ? DateDiffAllUnitsResultLabel : DateResultLabel); + String^ automationName = AutomationProperties::GetName(resultTextBlock); + TextBlockAutomationPeer::FromElement(resultTextBlock)->RaiseAutomationEvent(AutomationEvents::LiveRegionChanged); +} + +void CalculatorApp::DateCalculator::AddSubtractOption_Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) +{ + RaiseLiveRegionChangedAutomationEvent(false); } diff --git a/src/Calculator/Views/DateCalculator.xaml.h b/src/Calculator/Views/DateCalculator.xaml.h index 9c5303d7..65cdfa6f 100644 --- a/src/Calculator/Views/DateCalculator.xaml.h +++ b/src/Calculator/Views/DateCalculator.xaml.h @@ -38,9 +38,13 @@ namespace CalculatorApp void OnLoaded(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs^ e); void DateCalcOption_Changed(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e); void AddSubtractDateGrid_Loaded(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs^ e); + void AddSubtractOption_Checked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e); void ReselectCalendarDate(_In_ Windows::UI::Xaml::Controls::CalendarDatePicker^ calendarDatePicker, Windows::Foundation::DateTime dateTime); - void OnDateResultLabelChanged(Windows::UI::Xaml::DependencyObject ^ sender, Windows::UI::Xaml::DependencyProperty ^ dp); + void OffsetDropDownClosed(_In_ Platform::Object^ sender, _In_ Platform::Object^ e); + void CalendarFlyoutClosed(_In_ Platform::Object^ sender, _In_ Platform::Object^ e); + void RaiseLiveRegionChangedAutomationEvent(_In_ bool isDateDiffMode); Windows::Foundation::EventRegistrationToken m_dateCalcOptionChangedEventToken; + void AddOption_Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); }; }