Skip to content

Commit 0cc207c

Browse files
Merge branch 'master' into PR_Template-InstructionsClarification
2 parents 4c2ed0c + cec85d4 commit 0cc207c

File tree

5 files changed

+43
-36
lines changed

5 files changed

+43
-36
lines changed

Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/InAppNotification.Events.cs

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6-
using Microsoft.Toolkit.Uwp.Extensions;
76
using Windows.UI.Xaml;
8-
using Windows.UI.Xaml.Automation;
97
using Windows.UI.Xaml.Automation.Peers;
108

119
namespace Microsoft.Toolkit.Uwp.UI.Controls
@@ -35,19 +33,6 @@ public partial class InAppNotification
3533
/// </summary>
3634
public event InAppNotificationClosedEventHandler Closed;
3735

38-
private static void AutomateTextNotification(AutomationPeer peer, string message)
39-
{
40-
if (peer != null)
41-
{
42-
peer.SetFocus();
43-
peer.RaiseNotificationEvent(
44-
AutomationNotificationKind.Other,
45-
AutomationNotificationProcessing.ImportantMostRecent,
46-
StringExtensions.GetLocalized("WindowsCommunityToolkit_InAppNotification_Events_NewNotificationMessage", "/Microsoft.Toolkit.Uwp.UI.Controls/Resources") + message,
47-
Guid.NewGuid().ToString());
48-
}
49-
}
50-
5136
private void DismissButton_Click(object sender, RoutedEventArgs e)
5237
{
5338
Dismiss(InAppNotificationDismissKind.User);
@@ -74,21 +59,23 @@ private void OnCurrentStateChanged(object sender, VisualStateChangedEventArgs e)
7459
private void OnNotificationVisible()
7560
{
7661
Opened?.Invoke(this, EventArgs.Empty);
77-
SetValue(AutomationProperties.NameProperty, StringExtensions.GetLocalized("WindowsCommunityToolkit_InAppNotification_NameProperty", "/Microsoft.Toolkit.Uwp.UI.Controls/Resources"));
78-
if (ContentTemplateRoot != null)
79-
{
80-
var peer = FrameworkElementAutomationPeer.CreatePeerForElement(ContentTemplateRoot);
81-
if (Content?.GetType() == typeof(string))
82-
{
83-
AutomateTextNotification(peer, Content.ToString());
84-
}
85-
}
8662
}
8763

8864
private void OnNotificationCollapsed()
8965
{
9066
Closed?.Invoke(this, new InAppNotificationClosedEventArgs(_lastDismissKind));
9167
Visibility = Visibility.Collapsed;
9268
}
69+
70+
private void RaiseAutomationNotification()
71+
{
72+
if (!AutomationPeer.ListenerExists(AutomationEvents.LiveRegionChanged))
73+
{
74+
return;
75+
}
76+
77+
var peer = FrameworkElementAutomationPeer.CreatePeerForElement(this);
78+
peer.RaiseAutomationEvent(AutomationEvents.LiveRegionChanged);
79+
}
9380
}
9481
}

Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/InAppNotification.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
using System;
66
using System.Collections.Generic;
77
using System.Linq;
8+
using Microsoft.Toolkit.Uwp.Extensions;
9+
using Microsoft.Toolkit.Uwp.UI.Extensions;
810
using Windows.UI.Xaml;
11+
using Windows.UI.Xaml.Automation;
912
using Windows.UI.Xaml.Controls;
1013

1114
namespace Microsoft.Toolkit.Uwp.UI.Controls
@@ -59,6 +62,7 @@ protected override void OnApplyTemplate()
5962
{
6063
_dismissButton.Visibility = ShowDismissButton ? Visibility.Visible : Visibility.Collapsed;
6164
_dismissButton.Click += DismissButton_Click;
65+
AutomationProperties.SetName(_dismissButton, StringExtensions.GetLocalized("WindowsCommunityToolkit_InAppNotification_DismissButton_AutomationName", "Microsoft.Toolkit.Uwp.UI.Controls/Resources"));
6266
}
6367

6468
if (_visualStateGroup != null)
@@ -72,6 +76,8 @@ protected override void OnApplyTemplate()
7276
UpdateContent(firstNotification);
7377
VisualStateManager.GoToState(this, StateContentVisible, true);
7478
}
79+
80+
AutomationProperties.SetLabeledBy(this, VisualTree.FindDescendant<ContentPresenter>(this));
7581
}
7682

7783
/// <summary>
@@ -240,6 +246,8 @@ private void UpdateContent(NotificationOptions notificationOptions)
240246
_contentProvider.Content = content;
241247
break;
242248
}
249+
250+
RaiseAutomationNotification();
243251
}
244252

245253
/// <summary>
@@ -276,11 +284,11 @@ private void Show(NotificationOptions notificationOptions)
276284

277285
if (shouldDisplayImmediately)
278286
{
279-
UpdateContent(notificationOptions);
280-
281287
Visibility = Visibility.Visible;
282288
VisualStateManager.GoToState(this, StateContentVisible, true);
283289

290+
UpdateContent(notificationOptions);
291+
284292
if (notificationOptions.Duration > 0)
285293
{
286294
_dismissTimer.Interval = TimeSpan.FromMilliseconds(notificationOptions.Duration);

Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/InAppNotification.xaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
<Setter Property="AnimationDuration" Value="0:0:0.100" />
2929
<Setter Property="VerticalOffset" Value="100" />
3030
<Setter Property="HorizontalOffset" Value="0" />
31+
<Setter Property="AutomationProperties.LandmarkType" Value="Custom" />
32+
<!-- The setter value is localized using x:Uid but we still need to set it explicitly to avoid a compiler warning -->
33+
<Setter x:Uid="WindowsCommunityToolkit_InAppNotification_LandmarkProperty" Property="AutomationProperties.LocalizedLandmarkType" Value="Notification" />
34+
<Setter Property="AutomationProperties.LiveSetting" Value="Assertive" />
3135
<Setter Property="Template" Value="{StaticResource MSEdgeNotificationTemplate}" />
3236
</Style>
3337

Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/Styles/MSEdgeNotificationStyle.xaml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,18 @@
3131
</ResourceDictionary>
3232
</ResourceDictionary.ThemeDictionaries>
3333

34+
<x:Double x:Key="SystemControlMSEdgeNotificationDismissButtonSize">40</x:Double>
35+
<Thickness x:Key="SystemControlMSEdgeNotificationDismissButtonMargin">24,0,0,0</Thickness>
36+
<x:Double x:Key="SystemControlMSEdgeNotificationDismissButtonTranslate">18</x:Double>
37+
<VerticalAlignment x:Key="SystemControlMSEdgeNotificationDismissButtonVerticalAlignment">Center</VerticalAlignment>
38+
<Thickness x:Key="SystemControlMSEdgeNotificationButtonBorderThickness">2</Thickness>
39+
3440
<Style x:Key="DismissTextBlockButtonStyle"
3541
TargetType="ButtonBase">
3642
<Setter Property="Background" Value="{ThemeResource HyperlinkButtonBackground}" />
3743
<Setter Property="Foreground" Value="{ThemeResource ApplicationForegroundThemeBrush}" />
38-
<Setter Property="Width" Value="40" />
39-
<Setter Property="Height" Value="40" />
44+
<Setter Property="Width" Value="{StaticResource SystemControlMSEdgeNotificationDismissButtonSize}" />
45+
<Setter Property="Height" Value="{StaticResource SystemControlMSEdgeNotificationDismissButtonSize}" />
4046
<Setter Property="UseSystemFocusVisuals" Value="True" />
4147
<Setter Property="HighContrastAdjustment" Value="None" />
4248
<Setter Property="Template">
@@ -46,9 +52,10 @@
4652
Margin="{TemplateBinding Padding}"
4753
Background="{TemplateBinding Background}">
4854
<Border x:Name="TextBorder"
49-
BorderBrush="{ThemeResource SystemControlMSEdgeNotificationButtonBorderBrush}"
50-
BorderThickness="2">
55+
BorderThickness="{StaticResource SystemControlMSEdgeNotificationButtonBorderThickness}"
56+
BorderBrush="{ThemeResource SystemControlMSEdgeNotificationButtonBorderBrush}">
5157
<ContentPresenter x:Name="Text"
58+
AutomationProperties.AccessibilityView="Raw"
5259
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
5360
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
5461
Content="{TemplateBinding Content}" />
@@ -143,11 +150,12 @@
143150

144151
<Button x:Name="PART_DismissButton"
145152
Grid.Column="1"
146-
Margin="24,0,0,0"
153+
Margin="{StaticResource SystemControlMSEdgeNotificationDismissButtonMargin}"
147154
AutomationProperties.Name="Dismiss"
148155
Content="&#xE894;"
149156
FontFamily="Segoe MDL2 Assets"
150157
FontSize="16"
158+
VerticalAlignment="{StaticResource SystemControlMSEdgeNotificationDismissButtonVerticalAlignment}"
151159
Style="{StaticResource DismissTextBlockButtonStyle}">
152160
<Button.RenderTransform>
153161
<TranslateTransform x:Name="DismissButtonTransform" X="18" />

Microsoft.Toolkit.Uwp.UI.Controls/Strings/en-US/Resources.resw

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,13 @@
205205
<value>GridSplitter</value>
206206
<comment>Narrator Resource for GridSplitter control</comment>
207207
</data>
208-
<data name="WindowsCommunityToolkit_InAppNotification_Events_NewNotificationMessage" xml:space="preserve">
209-
<value>New notification</value>
210-
<comment>Narrator resource for a new notification using the InAppNotification</comment>
208+
<data name="WindowsCommunityToolkit_InAppNotification_DismissButton_AutomationName" xml:space="preserve">
209+
<value>Dismiss</value>
210+
<comment>The automation name for the dismiss button of the InAppNotification control.</comment>
211211
</data>
212-
<data name="WindowsCommunityToolkit_InAppNotification_NameProperty" xml:space="preserve">
212+
<data name="WindowsCommunityToolkit_InAppNotification_LandmarkProperty.Value" xml:space="preserve">
213213
<value>Notification</value>
214-
<comment>Name property for InAppNotification</comment>
214+
<comment>The landmark name for the InAppNotification control. It is said by the narrator when using landmark navigation.</comment>
215215
</data>
216216
<data name="WindowsCommunityToolkit_TabView_CloseButton.[using:Windows.UI.Xaml.Automation]AutomationProperties.Name" xml:space="preserve">
217217
<value>Close tab</value>

0 commit comments

Comments
 (0)