Skip to content

Commit ff19ced

Browse files
authored
Merge pull request #317 from CommunityToolkit/niels9001/narrator-settingscontrols
[SettingsControls] Narrator improvements
2 parents 3882ace + 02ceaad commit ff19ced

File tree

5 files changed

+17
-38
lines changed

5 files changed

+17
-38
lines changed

labs/SettingsControls/src/CommunityToolkit.Labs.WinUI.SettingsControls.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<Description>
1919
This package contains the SettingsCard and SettingsExpander controls.
2020
</Description>
21-
<Version>0.0.8</Version>
21+
<Version>0.0.9</Version>
2222
<LangVersion>10.0</LangVersion>
2323
</PropertyGroup>
2424

labs/SettingsControls/src/SettingsCard/SettingsCard.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,13 @@ protected override void OnApplyTemplate()
4949

5050
private void RegisterAutomation()
5151
{
52-
if (Header != null && Header.GetType() == typeof(string))
52+
if (Header is string headerString && headerString != string.Empty)
5353
{
54-
string? headerString = Header.ToString();
55-
if (!string.IsNullOrEmpty(headerString))
54+
AutomationProperties.SetName(this, headerString);
55+
// We don't want to override an AutomationProperties.Name that is manually set, or if the Content basetype is of type ButtonBase (the ButtonBase.Content will be used then)
56+
if (Content is UIElement element && string.IsNullOrEmpty(AutomationProperties.GetName(element)) && element.GetType().BaseType != typeof(ButtonBase))
5657
{
57-
AutomationProperties.SetName(this, headerString);
58-
}
59-
60-
if (Content != null && Content.GetType() != typeof(Button))
61-
{
62-
// We do not want to override the default AutomationProperties.Name of a button. Its Content property already describes what it does.
63-
if (!string.IsNullOrEmpty(headerString))
64-
{
65-
AutomationProperties.SetName((UIElement)Content, headerString);
66-
}
58+
AutomationProperties.SetName(element, headerString);
6759
}
6860
}
6961
}

labs/SettingsControls/src/SettingsExpander/SettingsExpander.Properties.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public partial class SettingsExpander
4040
/// </summary>
4141
public static readonly DependencyProperty ContentProperty = DependencyProperty.Register(
4242
nameof(Content),
43-
typeof(UIElement),
43+
typeof(object),
4444
typeof(SettingsExpander),
4545
new PropertyMetadata(defaultValue: null));
4646

@@ -87,9 +87,9 @@ public IconElement HeaderIcon
8787
/// <summary>
8888
/// Gets or sets the Content.
8989
/// </summary>
90-
public UIElement Content
90+
public object Content
9191
{
92-
get => (UIElement)GetValue(ContentProperty);
92+
get => (object)GetValue(ContentProperty);
9393
set => SetValue(ContentProperty, value);
9494
}
9595

labs/SettingsControls/src/SettingsExpander/SettingsExpander.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,13 @@ protected override void OnApplyTemplate()
2727

2828
private void RegisterAutomation()
2929
{
30-
if (Header != null && Header.GetType() == typeof(string))
30+
if (Header is string headerString && headerString != string.Empty)
3131
{
32-
string? headerString = Header.ToString();
33-
if (!string.IsNullOrEmpty(headerString))
32+
if (!string.IsNullOrEmpty(headerString) && string.IsNullOrEmpty(AutomationProperties.GetName(this)))
3433
{
3534
AutomationProperties.SetName(this, headerString);
3635
}
37-
38-
if (Content != null && Content.GetType() != typeof(Button))
39-
{
40-
// We do not want to override the default AutomationProperties.Name of a button. Its Content property already describes what it does.
41-
if (!string.IsNullOrEmpty(headerString))
42-
{
43-
AutomationProperties.SetName((UIElement)Content, headerString);
44-
}
45-
}
4636
}
47-
4837
}
4938

5039
/// <summary>

labs/SettingsControls/src/SettingsExpander/SettingsExpander.xaml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
1+
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
22
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:animatedvisuals="using:Microsoft.UI.Xaml.Controls.AnimatedVisuals"
@@ -53,8 +53,6 @@
5353
<Setter Property="BorderThickness" Value="{ThemeResource SettingsCardBorderThickness}" />
5454
<Setter Property="CornerRadius" Value="{ThemeResource ControlCornerRadius}" />
5555
<Setter Property="MinHeight" Value="{ThemeResource SettingsCardMinHeight}" />
56-
<!--<Setter Property="win:AutomationProperties.AutomationControlType" Value="Group" />-->
57-
<!--<Setter Property="win:AutomationProperties.Name" Value="{TemplateBinding Header}" />-->
5856
<Setter Property="MaxWidth" Value="{ThemeResource SettingsCardMaxWidth}" />
5957
<Setter Property="MinWidth" Value="{ThemeResource SettingsCardMinWidth}" />
6058
<Setter Property="IsTabStop" Value="False" />
@@ -75,8 +73,9 @@
7573
<muxc:Expander MaxWidth="{TemplateBinding MaxWidth}"
7674
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
7775
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
76+
win:AutomationProperties.HelpText="{TemplateBinding AutomationProperties.HelpText}"
77+
win:AutomationProperties.Name="{TemplateBinding AutomationProperties.Name}"
7878
IsExpanded="{Binding IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
79-
IsTabStop="False"
8079
Style="{StaticResource SettingsExpanderExpanderStyle}">
8180
<muxc:Expander.Header>
8281
<labs:SettingsCard Padding="{StaticResource SettingsExpanderHeaderPadding}"
@@ -101,7 +100,6 @@
101100

102101
<Style x:Key="SettingsExpanderExpanderStyle"
103102
TargetType="muxc:Expander">
104-
<Setter Property="IsTabStop" Value="False" />
105103
<Setter Property="Background" Value="{ThemeResource ExpanderContentBackground}" />
106104
<Setter Property="BackgroundSizing" Value="InnerBorderEdge" />
107105
<Setter Property="MinWidth" Value="{ThemeResource FlyoutThemeMinWidth}" />
@@ -230,6 +228,7 @@
230228
HorizontalContentAlignment="{StaticResource ExpanderHeaderHorizontalContentAlignment}"
231229
VerticalContentAlignment="{StaticResource ExpanderHeaderVerticalContentAlignment}"
232230
win:AutomationProperties.AutomationId="ExpanderToggleButton"
231+
win:AutomationProperties.Name="{TemplateBinding AutomationProperties.Name}"
233232
BackgroundSizing="{TemplateBinding BackgroundSizing}"
234233
BorderBrush="{ThemeResource ExpanderHeaderBorderBrush}"
235234
BorderThickness="{ThemeResource ExpanderHeaderBorderThickness}"
@@ -239,7 +238,7 @@
239238
CornerRadius="{TemplateBinding CornerRadius}"
240239
IsChecked="{Binding Path=IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
241240
IsEnabled="{TemplateBinding IsEnabled}"
242-
IsTabStop="False"
241+
IsTabStop="True"
243242
Style="{StaticResource SettingsExpanderHeaderDownStyle}" />
244243
<!-- The clip is a composition clip applied in code -->
245244
<Border x:Name="ExpanderContentClip"
@@ -523,13 +522,12 @@
523522
VerticalAlignment="Center"
524523
HorizontalContentAlignment="Center"
525524
VerticalContentAlignment="Center"
526-
win:AutomationProperties.Name="{StaticResource SettingsExpanderChevronToolTip}"
527525
Background="{ThemeResource ExpanderChevronBackground}"
528526
BorderBrush="{ThemeResource ExpanderChevronBorderBrush}"
529527
BorderThickness="{ThemeResource ExpanderChevronBorderThickness}"
530528
CornerRadius="{ThemeResource ControlCornerRadius}"
531529
FocusVisualMargin="-3"
532-
IsTabStop="True"
530+
IsTabStop="False"
533531
ToolTipService.ToolTip="{StaticResource SettingsExpanderChevronToolTip}"
534532
UseSystemFocusVisuals="True">
535533
<muxc:AnimatedIcon x:Name="ExpandCollapseChevron"

0 commit comments

Comments
 (0)