From df7b3950be905720cda6af17d49e05c303425c90 Mon Sep 17 00:00:00 2001 From: Stephanie Anderl <46726333+sanderl@users.noreply.github.com> Date: Fri, 1 Mar 2019 16:02:36 -0800 Subject: [PATCH] Updated the DateCalculation narrator logic to use PropertyChangedCallbacks for the DateResultLabel and DateDiffAllUnitsResultLabel TextBlocks. --- .../Automation/NarratorAnnouncement.cpp | 2 +- .../Common/Automation/NarratorAnnouncement.h | 10 ++++++--- src/Calculator/Views/DateCalculator.xaml | 7 +----- src/Calculator/Views/DateCalculator.xaml.cpp | 22 ++++++------------- src/Calculator/Views/DateCalculator.xaml.h | 6 ++--- 5 files changed, 18 insertions(+), 29 deletions(-) diff --git a/src/CalcViewModel/Common/Automation/NarratorAnnouncement.cpp b/src/CalcViewModel/Common/Automation/NarratorAnnouncement.cpp index 72b4a712..86f15ca8 100644 --- a/src/CalcViewModel/Common/Automation/NarratorAnnouncement.cpp +++ b/src/CalcViewModel/Common/Automation/NarratorAnnouncement.cpp @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #include "pch.h" diff --git a/src/CalcViewModel/Common/Automation/NarratorAnnouncement.h b/src/CalcViewModel/Common/Automation/NarratorAnnouncement.h index 16635b4a..0a5e3758 100644 --- a/src/CalcViewModel/Common/Automation/NarratorAnnouncement.h +++ b/src/CalcViewModel/Common/Automation/NarratorAnnouncement.h @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #pragma once @@ -57,7 +57,7 @@ namespace CalculatorApp::Common::Automation private: // Make CalculatorAnnouncement a friend class so it is the only // class that can access the private constructor. - friend class CalculatorAnnouncement; + friend ref class CalculatorAnnouncement; NarratorAnnouncement( Platform::String^ announcement, @@ -73,7 +73,7 @@ namespace CalculatorApp::Common::Automation // CalculatorAnnouncement is intended to contain only static methods // that return announcements made for the Calculator app. - class CalculatorAnnouncement + public ref class CalculatorAnnouncement sealed { public: static NarratorAnnouncement^ GetDisplayUpdatedAnnouncement(Platform::String^ announcement); @@ -90,5 +90,9 @@ namespace CalculatorApp::Common::Automation static NarratorAnnouncement^ GetUpdateCurrencyRatesAnnouncement(Platform::String^ announcement); static NarratorAnnouncement^ GetDisplayCopiedAnnouncement(Platform::String^ announcement); + + private: + CalculatorAnnouncement() { } }; + } diff --git a/src/Calculator/Views/DateCalculator.xaml b/src/Calculator/Views/DateCalculator.xaml index 4bb8d5b1..5eb4e58b 100644 --- a/src/Calculator/Views/DateCalculator.xaml +++ b/src/Calculator/Views/DateCalculator.xaml @@ -1,6 +1,7 @@ @@ -444,7 +444,6 @@ Style="{StaticResource DateCalculation_CalendarPickerStyle}" AutomationProperties.LabeledBy="{x:Bind Date_ToLabel}" CalendarViewStyle="{StaticResource DateCalculation_CalendarViewStyle}" - Closed="CalendarFlyoutClosed" DateChanged="ToDate_DateChanged"/> @@ -502,7 +501,6 @@ Style="{StaticResource DateCalculation_CalendarPickerStyle}" AutomationProperties.LabeledBy="{x:Bind AddSubtract_Date_FromLabel}" CalendarViewStyle="{StaticResource DateCalculation_CalendarViewStyle}" - Closed="CalendarFlyoutClosed" DateChanged="AddSubtract_DateChanged"/> @@ -551,7 +549,6 @@ 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"/> @@ -567,7 +564,6 @@ 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"/> @@ -582,7 +578,6 @@ 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 be7b7378..2e6ff459 100644 --- a/src/Calculator/Views/DateCalculator.xaml.cpp +++ b/src/Calculator/Views/DateCalculator.xaml.cpp @@ -182,6 +182,10 @@ 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) @@ -207,20 +211,8 @@ void DateCalculator::ReselectCalendarDate(_In_ Windows::UI::Xaml::Controls::Cale calendarDatePicker->IsCalendarOpen = false; } -void DateCalculator::OffsetDropDownClosed(_In_ Object^ sender, _In_ Object^ e) +void DateCalculator::OnDateResultLabelChanged(Windows::UI::Xaml::DependencyObject^ sender, Windows::UI::Xaml::DependencyProperty^ dp) { - 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); + String^ automationName = AutomationProperties::GetName(sender); + TextBlockAutomationPeer::FromElement((TextBlock^)sender)->RaiseAutomationEvent(AutomationEvents::LiveRegionChanged); } diff --git a/src/Calculator/Views/DateCalculator.xaml.h b/src/Calculator/Views/DateCalculator.xaml.h index ad5917a5..9c5303d7 100644 --- a/src/Calculator/Views/DateCalculator.xaml.h +++ b/src/Calculator/Views/DateCalculator.xaml.h @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. // @@ -39,9 +39,7 @@ namespace CalculatorApp 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 ReselectCalendarDate(_In_ Windows::UI::Xaml::Controls::CalendarDatePicker^ calendarDatePicker, Windows::Foundation::DateTime dateTime); - 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); + void OnDateResultLabelChanged(Windows::UI::Xaml::DependencyObject ^ sender, Windows::UI::Xaml::DependencyProperty ^ dp); Windows::Foundation::EventRegistrationToken m_dateCalcOptionChangedEventToken; };