Fix: Narrator doesn't announce "There's no history yet" (#2116)

* provide UIA names properly

* fix ui testing
This commit is contained in:
Tian L 2024-02-01 18:40:22 +08:00 committed by GitHub
commit f69f74b59c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 43 additions and 5 deletions

View file

@ -2778,11 +2778,11 @@
<comment>{Locked}The Octal button</comment> <comment>{Locked}The Octal button</comment>
</data> </data>
<data name="HistoryEmpty.Text" xml:space="preserve"> <data name="HistoryEmpty.Text" xml:space="preserve">
<value>Theres no history yet</value> <value>Theres no history yet.</value>
<comment>The text that shows as the header for the history list</comment> <comment>The text that shows as the header for the history list</comment>
</data> </data>
<data name="MemoryPaneEmpty.Text" xml:space="preserve"> <data name="MemoryPaneEmpty.Text" xml:space="preserve">
<value>Theres nothing saved in memory</value> <value>Theres nothing saved in memory.</value>
<comment>The text that shows as the header for the memory list</comment> <comment>The text that shows as the header for the memory list</comment>
</data> </data>
<data name="MemoryFlyout.[using:Windows.UI.Xaml.Automation]AutomationProperties.Name" xml:space="preserve"> <data name="MemoryFlyout.[using:Windows.UI.Xaml.Automation]AutomationProperties.Name" xml:space="preserve">

View file

@ -1375,7 +1375,7 @@
<PivotItem x:Name="HistoryPivotItem" <PivotItem x:Name="HistoryPivotItem"
Margin="0,10,0,0" Margin="0,10,0,0"
AutomationProperties.AutomationId="HistoryLabel" AutomationProperties.AutomationId="HistoryLabel"
AutomationProperties.Name="{utils:ResourceString Name=HistoryPivotItem/[using:Windows.UI.Xaml.Automation]AutomationProperties/Name}"> AutomationProperties.Name="{x:Bind HistoryPivotItemUiaName, Mode=OneWay}">
<PivotItem.Header> <PivotItem.Header>
<TextBlock AccessKey="{utils:ResourceString Name=HistoryLabel/AccessKey}" <TextBlock AccessKey="{utils:ResourceString Name=HistoryLabel/AccessKey}"
AccessKeyInvoked="OnHistoryAccessKeyInvoked" AccessKeyInvoked="OnHistoryAccessKeyInvoked"
@ -1386,7 +1386,7 @@
<PivotItem x:Name="MemoryPivotItem" <PivotItem x:Name="MemoryPivotItem"
Margin="0,10,0,0" Margin="0,10,0,0"
AutomationProperties.AutomationId="MemoryLabel" AutomationProperties.AutomationId="MemoryLabel"
AutomationProperties.Name="{utils:ResourceString Name=MemoryPivotItem/[using:Windows.UI.Xaml.Automation]AutomationProperties/Name}"> AutomationProperties.Name="{x:Bind MemoryPivotItemUiaName, Mode=OneWay}">
<PivotItem.Header> <PivotItem.Header>
<TextBlock AccessKey="{utils:ResourceString Name=MemoryLabel/AccessKey}" <TextBlock AccessKey="{utils:ResourceString Name=MemoryLabel/AccessKey}"
AccessKeyInvoked="OnMemoryAccessKeyInvoked" AccessKeyInvoked="OnMemoryAccessKeyInvoked"

View file

@ -6,7 +6,7 @@ using CalculatorApp.ViewModel;
using CalculatorApp.ViewModel.Common; using CalculatorApp.ViewModel.Common;
using System; using System;
using Windows.ApplicationModel.Resources;
using Windows.Foundation; using Windows.Foundation;
using Windows.Globalization.NumberFormatting; using Windows.Globalization.NumberFormatting;
using Windows.UI.Core; using Windows.UI.Core;
@ -120,6 +120,26 @@ namespace CalculatorApp
self.OnIsAlwaysOnTopPropertyChanged((bool)args.OldValue, (bool)args.NewValue); self.OnIsAlwaysOnTopPropertyChanged((bool)args.OldValue, (bool)args.NewValue);
})); }));
public string HistoryPivotItemUiaName
{
get => (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 public System.Windows.Input.ICommand HistoryButtonPressed
{ {
get get
@ -159,6 +179,7 @@ namespace CalculatorApp
{ {
if (m_historyList == null) if (m_historyList == null)
{ {
historyVM.PropertyChanged += (s, e) => UpdateHistoryState();
m_historyList = new HistoryList m_historyList = new HistoryList
{ {
DataContext = historyVM DataContext = historyVM
@ -168,6 +189,7 @@ namespace CalculatorApp
} }
} }
public void UpdatePanelViewState() public void UpdatePanelViewState()
{ {
UpdateHistoryState(); UpdateHistoryState();
@ -296,6 +318,7 @@ namespace CalculatorApp
MemRecall.IsEnabled = false; MemRecall.IsEnabled = false;
ClearMemoryButton.IsEnabled = false; ClearMemoryButton.IsEnabled = false;
} }
MemoryPivotItemUiaName = GetMemoryPivotItemUiaString(Model.IsMemoryEmpty);
if (DockPanel.Visibility == Visibility.Visible) if (DockPanel.Visibility == Visibility.Visible)
{ {
@ -328,6 +351,7 @@ namespace CalculatorApp
{ {
DockPivot.SelectedIndex = 0; DockPivot.SelectedIndex = 0;
} }
HistoryPivotItemUiaName = GetHistoryPivotItemUiaString(Model.HistoryVM.ItemsCount == 0);
} }
else else
{ {
@ -843,5 +867,19 @@ namespace CalculatorApp
var mode = IsStandard ? ViewMode.Standard : IsScientific ? ViewMode.Scientific : ViewMode.Programmer; var mode = IsStandard ? ViewMode.Standard : IsScientific ? ViewMode.Scientific : ViewMode.Programmer;
TraceLogger.GetInstance().LogVisualStateChanged(mode, e.NewState.Name, IsAlwaysOnTop); 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;
}
} }
} }