diff options
author | Eric Maupin <ermaup@microsoft.com> | 2019-09-09 22:39:17 +0300 |
---|---|---|
committer | Eric Maupin <ermaup@microsoft.com> | 2019-09-09 23:00:00 +0300 |
commit | ab42eb3a08ad8cb9ce8948b02c5553e951227821 (patch) | |
tree | 3694498f49e90af7c02b5c38b5288cec3b569c79 /Xamarin.PropertyEditing.Windows | |
parent | 3674cf84d45f00ab89d6d377a6e374a5725432b8 (diff) |
[Win] A11y exclude input modes when hidden
In WPF, even if a control is collapsed, automation will still pick
it up. So we need to use our own automation peers to eliminate it
from the automation tree if it's not visible.
Diffstat (limited to 'Xamarin.PropertyEditing.Windows')
-rw-r--r-- | Xamarin.PropertyEditing.Windows/ComboBoxEx.cs | 20 | ||||
-rw-r--r-- | Xamarin.PropertyEditing.Windows/Themes/Resources.xaml | 17 | ||||
-rw-r--r-- | Xamarin.PropertyEditing.Windows/ToggleButtonEx.cs | 25 |
3 files changed, 48 insertions, 14 deletions
diff --git a/Xamarin.PropertyEditing.Windows/ComboBoxEx.cs b/Xamarin.PropertyEditing.Windows/ComboBoxEx.cs index d4369ce..a66d18c 100644 --- a/Xamarin.PropertyEditing.Windows/ComboBoxEx.cs +++ b/Xamarin.PropertyEditing.Windows/ComboBoxEx.cs @@ -1,4 +1,5 @@ using System.Windows; +using System.Windows.Automation.Peers; using System.Windows.Controls; using System.Windows.Input; @@ -21,6 +22,11 @@ namespace Xamarin.PropertyEditing.Windows set { SetValue (EnableSubmitProperty, value); } } + protected override AutomationPeer OnCreateAutomationPeer () + { + return new ComboBoxExAutomationPeer (this); + } + protected override void OnSelectionChanged (SelectionChangedEventArgs e) { base.OnSelectionChanged (e); @@ -56,5 +62,19 @@ namespace Xamarin.PropertyEditing.Windows OnSubmit(); } + + private class ComboBoxExAutomationPeer + : ComboBoxAutomationPeer + { + public ComboBoxExAutomationPeer (ComboBox owner) + : base (owner) + { + } + + protected override bool IsControlElementCore () + { + return base.IsControlElementCore () && Owner.IsVisible; + } + } } } diff --git a/Xamarin.PropertyEditing.Windows/Themes/Resources.xaml b/Xamarin.PropertyEditing.Windows/Themes/Resources.xaml index 8fe6b96..7027ac6 100644 --- a/Xamarin.PropertyEditing.Windows/Themes/Resources.xaml +++ b/Xamarin.PropertyEditing.Windows/Themes/Resources.xaml @@ -287,13 +287,13 @@ </Grid.ColumnDefinitions> <local:TextBoxEx x:Name="TextBox" Grid.Column="0" FocusSelectsAll="True" AutomationProperties.Name="{Binding Property.Name,Mode=OneTime}" Text="{Binding Value,UpdateSourceTrigger=Explicit}" VerticalContentAlignment="Center" IsEnabled="{Binding IsInputEnabled}" /> - <ComboBox Grid.Column="1" Visibility="{Binding HasInputModes,Mode=OneTime,Converter={StaticResource BoolToVisibilityConverter}}" IsEnabled="{Binding Property.CanWrite,Mode=OneTime}" ItemsSource="{Binding InputModes,Mode=OneTime}" SelectedItem="{Binding InputMode,Mode=TwoWay}" DisplayMemberPath="Identifier"> - <ComboBox.ItemContainerStyle> + <local:ComboBoxEx Grid.Column="1" Visibility="{Binding HasInputModes,Mode=OneTime,Converter={StaticResource BoolToVisibilityConverter}}" IsEnabled="{Binding Property.CanWrite,Mode=OneTime}" EnableSubmit="False" ItemsSource="{Binding InputModes,Mode=OneTime}" SelectedItem="{Binding InputMode,Mode=TwoWay}" DisplayMemberPath="Identifier"> + <local:ComboBoxEx.ItemContainerStyle> <Style TargetType="ComboBoxItem"> <Setter Property="AutomationProperties.Name" Value="{Binding Identifier,Mode=OneTime}" /> </Style> - </ComboBox.ItemContainerStyle> - </ComboBox> + </local:ComboBoxEx.ItemContainerStyle> + </local:ComboBoxEx> </Grid> </ControlTemplate> </Setter.Value> @@ -2144,15 +2144,14 @@ </Grid.ColumnDefinitions> <ContentPresenter Grid.Column="0" Content="{Binding}" ContentTemplateSelector="{StaticResource NumericTemplateSelector}" AutomationProperties.Name="{Binding Property.Name,Mode=OneTime}" /> - <ComboBox Grid.Column="1" Visibility="{Binding HasInputModes,Mode=OneTime,Converter={StaticResource BoolToVisibilityConverter}}" IsEnabled="{Binding Property.CanWrite,Mode=OneTime}" ItemsSource="{Binding InputModes,Mode=OneTime}" SelectedItem="{Binding InputMode,Mode=TwoWay}" DisplayMemberPath="Identifier"> - <ComboBox.ItemContainerStyle> + <local:ComboBoxEx Grid.Column="1" Visibility="{Binding HasInputModes,Mode=OneTime,Converter={StaticResource BoolToVisibilityConverter}}" EnableSubmit="False" IsEnabled="{Binding Property.CanWrite,Mode=OneTime}" ItemsSource="{Binding InputModes,Mode=OneTime}" SelectedItem="{Binding InputMode,Mode=TwoWay}" DisplayMemberPath="Identifier"> + <local:ComboBoxEx.ItemContainerStyle> <Style TargetType="ComboBoxItem"> <Setter Property="AutomationProperties.Name" Value="{Binding Identifier,Mode=OneTime}" /> </Style> - </ComboBox.ItemContainerStyle> - </ComboBox> + </local:ComboBoxEx.ItemContainerStyle> + </local:ComboBoxEx> </Grid> - </ControlTemplate> </Setter.Value> </Setter> diff --git a/Xamarin.PropertyEditing.Windows/ToggleButtonEx.cs b/Xamarin.PropertyEditing.Windows/ToggleButtonEx.cs index b178b27..f2698aa 100644 --- a/Xamarin.PropertyEditing.Windows/ToggleButtonEx.cs +++ b/Xamarin.PropertyEditing.Windows/ToggleButtonEx.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; +using System.Windows.Automation.Peers; using System.Windows.Controls.Primitives; namespace Xamarin.PropertyEditing.Windows @@ -19,5 +15,24 @@ namespace Xamarin.PropertyEditing.Windows get { return (bool) GetValue (IsMouseOverRemoteProperty); } set { SetValue (IsMouseOverRemoteProperty, value); } } + + protected override AutomationPeer OnCreateAutomationPeer () + { + return new ToggleButtonExAutomationPeer (this); + } + + private class ToggleButtonExAutomationPeer + : ToggleButtonAutomationPeer + { + public ToggleButtonExAutomationPeer (ToggleButton owner) + : base (owner) + { + } + + protected override bool IsControlElementCore () + { + return base.IsControlElementCore () && Owner.IsVisible; + } + } } } |