[ColorPicker] Accessibility: Narrator announces color changes in main… (#12369)

* [ColorPicker] Accessibility: Narrator announces color changes in main view

* fixup: Announce color friendly name instead of numbers
This commit is contained in:
Andrey Nekrasov 2021-07-14 22:53:42 +03:00 committed by GitHub
parent 25a7bf9ab0
commit d583b083d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 7 deletions

View File

@ -118,10 +118,7 @@ namespace ColorPicker.ViewModels
{
ColorBrush = new SolidColorBrush(Color.FromArgb(color.A, color.R, color.G, color.B));
ColorText = ColorRepresentationHelper.GetStringRepresentation(color, _userSettings.CopiedColorRepresentation.Value);
if (_userSettings.ShowColorName.Value)
{
ColorName = ColorNameHelper.GetColorName(color);
}
ColorName = ColorNameHelper.GetColorName(color);
}
/// <summary>

View File

@ -35,14 +35,18 @@
VerticalAlignment="Stretch"
BorderBrush="{DynamicResource WindowBorderBrush}"
BorderThickness="1"
x:Name="ColorBorderSmall"
CornerRadius="4"/>
<TextBlock Margin="8,5,8,8"
<TextBlock
x:Name="ColorTextBlock"
Margin="8,5,8,8"
FontSize="16"
FontWeight="SemiBold"
Foreground="{DynamicResource PrimaryForegroundBrush}"
Grid.Column="1"
AutomationProperties.LiveSetting="Assertive"
AutomationProperties.LabeledBy="{Binding ColorName}"
AutomationProperties.Name="{Binding ColorName}"
Text="{Binding ColorText}"/>
</Grid>

View File

@ -2,6 +2,9 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.ComponentModel;
using System.Windows;
using System.Windows.Automation.Peers;
using System.Windows.Controls;
namespace ColorPicker.Views
@ -11,7 +14,41 @@ namespace ColorPicker.Views
/// </summary>
public partial class MainView : UserControl
{
private void EnableNarratorColorChangesAnnouncements()
{
INotifyPropertyChanged viewModel = (INotifyPropertyChanged)this.DataContext;
viewModel.PropertyChanged += (sender, args) =>
{
if (args.PropertyName != "ColorName")
{
return;
}
var colorTextBlock = (TextBlock)FindName("ColorTextBlock");
if (colorTextBlock == null)
{
return;
}
var peer = UIElementAutomationPeer.FromElement(colorTextBlock);
if (peer == null)
{
peer = UIElementAutomationPeer.CreatePeerForElement(colorTextBlock);
}
peer.RaiseAutomationEvent(AutomationEvents.MenuOpened);
};
}
private void OnLoaded(object sender, RoutedEventArgs e)
{
EnableNarratorColorChangesAnnouncements();
}
public MainView()
=> InitializeComponent();
{
InitializeComponent();
Loaded += OnLoaded;
}
}
}