From f69f74b59cb64a800f3c5b8dd3b8ad658158e8a9 Mon Sep 17 00:00:00 2001
From: Tian L <60599517+tian-lt@users.noreply.github.com>
Date: Thu, 1 Feb 2024 18:40:22 +0800
Subject: [PATCH] Fix: Narrator doesn't announce "There's no history yet"
(#2116)
* provide UIA names properly
* fix ui testing
---
src/Calculator/Resources/en-US/Resources.resw | 4 +-
src/Calculator/Views/Calculator.xaml | 4 +-
src/Calculator/Views/Calculator.xaml.cs | 40 ++++++++++++++++++-
3 files changed, 43 insertions(+), 5 deletions(-)
diff --git a/src/Calculator/Resources/en-US/Resources.resw b/src/Calculator/Resources/en-US/Resources.resw
index 5dbd92b0..3d27bd36 100644
--- a/src/Calculator/Resources/en-US/Resources.resw
+++ b/src/Calculator/Resources/en-US/Resources.resw
@@ -2778,11 +2778,11 @@
{Locked}The Octal button
- There’s no history yet
+ There’s no history yet.
The text that shows as the header for the history list
- There’s nothing saved in memory
+ There’s nothing saved in memory.
The text that shows as the header for the memory list
diff --git a/src/Calculator/Views/Calculator.xaml b/src/Calculator/Views/Calculator.xaml
index 933052a9..60db59c9 100644
--- a/src/Calculator/Views/Calculator.xaml
+++ b/src/Calculator/Views/Calculator.xaml
@@ -1375,7 +1375,7 @@
+ AutomationProperties.Name="{x:Bind HistoryPivotItemUiaName, Mode=OneWay}">
+ AutomationProperties.Name="{x:Bind MemoryPivotItemUiaName, Mode=OneWay}">
(string)GetValue(HistoryPivotItemUiaNameProperty);
+ set => SetValue(HistoryPivotItemUiaNameProperty, value);
+ }
+
+ // Using a DependencyProperty as the backing store for HistoryPivotItemUiaName. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty HistoryPivotItemUiaNameProperty =
+ DependencyProperty.Register(nameof(HistoryPivotItemUiaName), typeof(string), typeof(Calculator), new PropertyMetadata(string.Empty));
+
+ public string MemoryPivotItemUiaName
+ {
+ get => (string)GetValue(MemoryPivotItemUiaNameProperty);
+ set => SetValue(MemoryPivotItemUiaNameProperty, value);
+ }
+
+ // Using a DependencyProperty as the backing store for MemoryPivotItemUiaName. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty MemoryPivotItemUiaNameProperty =
+ DependencyProperty.Register(nameof(MemoryPivotItemUiaName), typeof(string), typeof(Calculator), new PropertyMetadata(string.Empty));
+
public System.Windows.Input.ICommand HistoryButtonPressed
{
get
@@ -159,6 +179,7 @@ namespace CalculatorApp
{
if (m_historyList == null)
{
+ historyVM.PropertyChanged += (s, e) => UpdateHistoryState();
m_historyList = new HistoryList
{
DataContext = historyVM
@@ -168,6 +189,7 @@ namespace CalculatorApp
}
}
+
public void UpdatePanelViewState()
{
UpdateHistoryState();
@@ -296,6 +318,7 @@ namespace CalculatorApp
MemRecall.IsEnabled = false;
ClearMemoryButton.IsEnabled = false;
}
+ MemoryPivotItemUiaName = GetMemoryPivotItemUiaString(Model.IsMemoryEmpty);
if (DockPanel.Visibility == Visibility.Visible)
{
@@ -328,6 +351,7 @@ namespace CalculatorApp
{
DockPivot.SelectedIndex = 0;
}
+ HistoryPivotItemUiaName = GetHistoryPivotItemUiaString(Model.HistoryVM.ItemsCount == 0);
}
else
{
@@ -843,5 +867,19 @@ namespace CalculatorApp
var mode = IsStandard ? ViewMode.Standard : IsScientific ? ViewMode.Scientific : ViewMode.Programmer;
TraceLogger.GetInstance().LogVisualStateChanged(mode, e.NewState.Name, IsAlwaysOnTop);
}
+
+ private string GetMemoryPivotItemUiaString(bool isEmpty)
+ {
+ var loader = ResourceLoader.GetForCurrentView();
+ var label = loader.GetString("MemoryLabel/Text");
+ return isEmpty ? $"{loader.GetString("MemoryPaneEmpty/Text")} {label}" : label;
+ }
+
+ private string GetHistoryPivotItemUiaString(bool isEmpty)
+ {
+ var loader = ResourceLoader.GetForCurrentView();
+ var label = loader.GetString("HistoryLabel/Text");
+ return isEmpty ? $"{loader.GetString("HistoryEmpty/Text")} {label}" : label;
+ }
}
}