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 коммит произвёл GitHub
Родитель c4cb05fe40
Коммит f69f74b59c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
3 изменённых файлов: 43 добавлений и 5 удалений

Просмотреть файл

@ -2778,11 +2778,11 @@
<comment>{Locked}The Octal button</comment>
</data>
<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>
</data>
<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>
</data>
<data name="MemoryFlyout.[using:Windows.UI.Xaml.Automation]AutomationProperties.Name" xml:space="preserve">

Просмотреть файл

@ -1375,7 +1375,7 @@
<PivotItem x:Name="HistoryPivotItem"
Margin="0,10,0,0"
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>
<TextBlock AccessKey="{utils:ResourceString Name=HistoryLabel/AccessKey}"
AccessKeyInvoked="OnHistoryAccessKeyInvoked"
@ -1386,7 +1386,7 @@
<PivotItem x:Name="MemoryPivotItem"
Margin="0,10,0,0"
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>
<TextBlock AccessKey="{utils:ResourceString Name=MemoryLabel/AccessKey}"
AccessKeyInvoked="OnMemoryAccessKeyInvoked"

Просмотреть файл

@ -6,7 +6,7 @@ using CalculatorApp.ViewModel;
using CalculatorApp.ViewModel.Common;
using System;
using Windows.ApplicationModel.Resources;
using Windows.Foundation;
using Windows.Globalization.NumberFormatting;
using Windows.UI.Core;
@ -120,6 +120,26 @@ namespace CalculatorApp
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
{
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;
}
}
}