mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-22 06:13:14 -07:00
Updated the DateCalculation narrator logic to use PropertyChangedCallbacks for the DateResultLabel and DateDiffAllUnitsResultLabel TextBlocks.
This commit is contained in:
parent
a342421603
commit
df7b3950be
5 changed files with 18 additions and 29 deletions
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
// Licensed under the MIT License.
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
// Licensed under the MIT License.
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
@ -57,7 +57,7 @@ namespace CalculatorApp::Common::Automation
|
||||||
private:
|
private:
|
||||||
// Make CalculatorAnnouncement a friend class so it is the only
|
// Make CalculatorAnnouncement a friend class so it is the only
|
||||||
// class that can access the private constructor.
|
// class that can access the private constructor.
|
||||||
friend class CalculatorAnnouncement;
|
friend ref class CalculatorAnnouncement;
|
||||||
|
|
||||||
NarratorAnnouncement(
|
NarratorAnnouncement(
|
||||||
Platform::String^ announcement,
|
Platform::String^ announcement,
|
||||||
|
@ -73,7 +73,7 @@ namespace CalculatorApp::Common::Automation
|
||||||
|
|
||||||
// CalculatorAnnouncement is intended to contain only static methods
|
// CalculatorAnnouncement is intended to contain only static methods
|
||||||
// that return announcements made for the Calculator app.
|
// that return announcements made for the Calculator app.
|
||||||
class CalculatorAnnouncement
|
public ref class CalculatorAnnouncement sealed
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static NarratorAnnouncement^ GetDisplayUpdatedAnnouncement(Platform::String^ announcement);
|
static NarratorAnnouncement^ GetDisplayUpdatedAnnouncement(Platform::String^ announcement);
|
||||||
|
@ -90,5 +90,9 @@ namespace CalculatorApp::Common::Automation
|
||||||
static NarratorAnnouncement^ GetUpdateCurrencyRatesAnnouncement(Platform::String^ announcement);
|
static NarratorAnnouncement^ GetUpdateCurrencyRatesAnnouncement(Platform::String^ announcement);
|
||||||
|
|
||||||
static NarratorAnnouncement^ GetDisplayCopiedAnnouncement(Platform::String^ announcement);
|
static NarratorAnnouncement^ GetDisplayCopiedAnnouncement(Platform::String^ announcement);
|
||||||
|
|
||||||
|
private:
|
||||||
|
CalculatorAnnouncement() { }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<UserControl x:Class="CalculatorApp.DateCalculator"
|
<UserControl x:Class="CalculatorApp.DateCalculator"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:automation="using:CalculatorApp.Common.Automation"
|
||||||
xmlns:controls="using:CalculatorApp.Controls"
|
xmlns:controls="using:CalculatorApp.Controls"
|
||||||
xmlns:converters="using:CalculatorApp.Converters"
|
xmlns:converters="using:CalculatorApp.Converters"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
@ -428,7 +429,6 @@
|
||||||
Style="{StaticResource DateCalculation_CalendarPickerStyle}"
|
Style="{StaticResource DateCalculation_CalendarPickerStyle}"
|
||||||
AutomationProperties.LabeledBy="{x:Bind Date_FromLabel}"
|
AutomationProperties.LabeledBy="{x:Bind Date_FromLabel}"
|
||||||
CalendarViewStyle="{StaticResource DateCalculation_CalendarViewStyle}"
|
CalendarViewStyle="{StaticResource DateCalculation_CalendarViewStyle}"
|
||||||
Closed="CalendarFlyoutClosed"
|
|
||||||
DateChanged="FromDate_DateChanged"/>
|
DateChanged="FromDate_DateChanged"/>
|
||||||
|
|
||||||
<!-- To Date -->
|
<!-- To Date -->
|
||||||
|
@ -444,7 +444,6 @@
|
||||||
Style="{StaticResource DateCalculation_CalendarPickerStyle}"
|
Style="{StaticResource DateCalculation_CalendarPickerStyle}"
|
||||||
AutomationProperties.LabeledBy="{x:Bind Date_ToLabel}"
|
AutomationProperties.LabeledBy="{x:Bind Date_ToLabel}"
|
||||||
CalendarViewStyle="{StaticResource DateCalculation_CalendarViewStyle}"
|
CalendarViewStyle="{StaticResource DateCalculation_CalendarViewStyle}"
|
||||||
Closed="CalendarFlyoutClosed"
|
|
||||||
DateChanged="ToDate_DateChanged"/>
|
DateChanged="ToDate_DateChanged"/>
|
||||||
|
|
||||||
<!-- Difference Result -->
|
<!-- Difference Result -->
|
||||||
|
@ -502,7 +501,6 @@
|
||||||
Style="{StaticResource DateCalculation_CalendarPickerStyle}"
|
Style="{StaticResource DateCalculation_CalendarPickerStyle}"
|
||||||
AutomationProperties.LabeledBy="{x:Bind AddSubtract_Date_FromLabel}"
|
AutomationProperties.LabeledBy="{x:Bind AddSubtract_Date_FromLabel}"
|
||||||
CalendarViewStyle="{StaticResource DateCalculation_CalendarViewStyle}"
|
CalendarViewStyle="{StaticResource DateCalculation_CalendarViewStyle}"
|
||||||
Closed="CalendarFlyoutClosed"
|
|
||||||
DateChanged="AddSubtract_DateChanged"/>
|
DateChanged="AddSubtract_DateChanged"/>
|
||||||
|
|
||||||
<Grid Grid.Row="4">
|
<Grid Grid.Row="4">
|
||||||
|
@ -551,7 +549,6 @@
|
||||||
Grid.Row="1"
|
Grid.Row="1"
|
||||||
MinWidth="84"
|
MinWidth="84"
|
||||||
AutomationProperties.LabeledBy="{Binding ElementName=YearsLabel}"
|
AutomationProperties.LabeledBy="{Binding ElementName=YearsLabel}"
|
||||||
DropDownClosed="OffsetDropDownClosed"
|
|
||||||
ItemsSource="{Binding OffsetValues, Mode=OneTime}"
|
ItemsSource="{Binding OffsetValues, Mode=OneTime}"
|
||||||
SelectedIndex="{Binding YearsOffset, Mode=TwoWay}"
|
SelectedIndex="{Binding YearsOffset, Mode=TwoWay}"
|
||||||
SelectionChanged="OffsetValue_Changed"/>
|
SelectionChanged="OffsetValue_Changed"/>
|
||||||
|
@ -567,7 +564,6 @@
|
||||||
MinWidth="84"
|
MinWidth="84"
|
||||||
Margin="12,0,12,0"
|
Margin="12,0,12,0"
|
||||||
AutomationProperties.LabeledBy="{Binding ElementName=MonthsLabel}"
|
AutomationProperties.LabeledBy="{Binding ElementName=MonthsLabel}"
|
||||||
DropDownClosed="OffsetDropDownClosed"
|
|
||||||
ItemsSource="{Binding OffsetValues, Mode=OneTime}"
|
ItemsSource="{Binding OffsetValues, Mode=OneTime}"
|
||||||
SelectedIndex="{Binding MonthsOffset, Mode=TwoWay}"
|
SelectedIndex="{Binding MonthsOffset, Mode=TwoWay}"
|
||||||
SelectionChanged="OffsetValue_Changed"/>
|
SelectionChanged="OffsetValue_Changed"/>
|
||||||
|
@ -582,7 +578,6 @@
|
||||||
Grid.Column="2"
|
Grid.Column="2"
|
||||||
MinWidth="84"
|
MinWidth="84"
|
||||||
AutomationProperties.LabeledBy="{Binding ElementName=DaysLabel}"
|
AutomationProperties.LabeledBy="{Binding ElementName=DaysLabel}"
|
||||||
DropDownClosed="OffsetDropDownClosed"
|
|
||||||
ItemsSource="{Binding OffsetValues, Mode=OneTime}"
|
ItemsSource="{Binding OffsetValues, Mode=OneTime}"
|
||||||
SelectedIndex="{Binding DaysOffset, Mode=TwoWay}"
|
SelectedIndex="{Binding DaysOffset, Mode=TwoWay}"
|
||||||
SelectionChanged="OffsetValue_Changed"/>
|
SelectionChanged="OffsetValue_Changed"/>
|
||||||
|
|
|
@ -182,6 +182,10 @@ void DateCalculator::DateCalcOption_Changed(_In_ Platform::Object^ sender, _In_
|
||||||
{
|
{
|
||||||
FindName("AddSubtractDateGrid");
|
FindName("AddSubtractDateGrid");
|
||||||
DateCalculationOption->SelectionChanged -= m_dateCalcOptionChangedEventToken;
|
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)
|
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;
|
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);
|
String^ automationName = AutomationProperties::GetName(sender);
|
||||||
}
|
TextBlockAutomationPeer::FromElement((TextBlock^)sender)->RaiseAutomationEvent(AutomationEvents::LiveRegionChanged);
|
||||||
|
|
||||||
void DateCalculator::CalendarFlyoutClosed(_In_ Object^ sender, _In_ Object^ e)
|
|
||||||
{
|
|
||||||
auto dateCalcViewModel = safe_cast<DateCalculatorViewModel^>(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);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
// Licensed under the MIT License.
|
// 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 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 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 ReselectCalendarDate(_In_ Windows::UI::Xaml::Controls::CalendarDatePicker^ calendarDatePicker, Windows::Foundation::DateTime dateTime);
|
||||||
void OffsetDropDownClosed(_In_ Platform::Object^ sender, _In_ Platform::Object^ e);
|
void OnDateResultLabelChanged(Windows::UI::Xaml::DependencyObject ^ sender, Windows::UI::Xaml::DependencyProperty ^ dp);
|
||||||
void CalendarFlyoutClosed(_In_ Platform::Object^ sender, _In_ Platform::Object^ e);
|
|
||||||
void RaiseLiveRegionChangedAutomationEvent(_In_ bool isDateDiffMode);
|
|
||||||
|
|
||||||
Windows::Foundation::EventRegistrationToken m_dateCalcOptionChangedEventToken;
|
Windows::Foundation::EventRegistrationToken m_dateCalcOptionChangedEventToken;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue