[ColorPicker] Accessibility: announce color format for "Copy to clipboard" button (#13558)

This commit is contained in:
Andrey Nekrasov
2021-10-01 16:53:56 +03:00
committed by GitHub
parent 8aae821e59
commit 55054f1fa6
2 changed files with 16 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
<UserControl x:Class="ColorPicker.Controls.ColorFormatControl"
xmlns:local="clr-namespace:ColorPicker"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
@@ -50,7 +51,8 @@
Width="36"
Grid.Column="2"
AutomationProperties.Name="{x:Static p:Resources.Copy_to_clipboard}"
AutomationProperties.HelpText="{Binding ElementName=ColorTextRepresentationTextBlock, Path=Text}"
AutomationProperties.HelpText="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:Controls.ColorFormatControl}}, Path=SelectedColorCopyHelperText}"
FontSize="12"
Style="{StaticResource DefaultButtonStyle}"
FontFamily="Segoe MDL2 Assets">

View File

@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Automation.Peers;
using System.Windows.Controls;
@@ -23,6 +24,8 @@ namespace ColorPicker.Controls
public static readonly DependencyProperty SelectedColorProperty = DependencyProperty.Register("SelectedColor", typeof(Color), typeof(ColorFormatControl), new PropertyMetadata(SelectedColorPropertyChanged));
public static readonly DependencyProperty SelectedColorCopyHelperTextProperty = DependencyProperty.Register("SelectedColorCopyHelperText", typeof(string), typeof(ColorFormatControl));
public static readonly DependencyProperty ColorCopiedNotificationBorderProperty = DependencyProperty.Register("ColorCopiedNotificationBorder", typeof(FrameworkElement), typeof(ColorFormatControl), new PropertyMetadata(ColorCopiedBorderPropertyChanged));
private const int CopyIndicatorStayTimeInMs = 3000;
@@ -47,6 +50,12 @@ namespace ColorPicker.Controls
set { SetValue(ColorCopiedNotificationBorderProperty, value); }
}
public string SelectedColorCopyHelperText
{
get { return (string)GetValue(SelectedColorCopyHelperTextProperty); }
set { SetValue(SelectedColorCopyHelperTextProperty, value); }
}
public ColorFormatControl()
{
InitializeComponent();
@@ -68,7 +77,10 @@ namespace ColorPicker.Controls
private static void SelectedColorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((ColorFormatControl)d).ColorTextRepresentationTextBlock.Text = ((ColorFormatControl)d).ColorFormatModel.Convert((Color)e.NewValue);
var self = (ColorFormatControl)d;
var colorText = self.ColorFormatModel.Convert((Color)e.NewValue);
self.ColorTextRepresentationTextBlock.Text = colorText;
self.SelectedColorCopyHelperText = string.Format(CultureInfo.InvariantCulture, "{0} {1}", self.ColorFormatModel.FormatName, colorText);
}
private static void ColorFormatModelPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)