Skip to content

Commit 971c68f

Browse files
authored
Merge pull request #3306 from windows-toolkit/inAppNotificationNagivationFix
Fix for #2899.
2 parents 02577b5 + c1dbb3b commit 971c68f

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ public partial class InAppNotification
3535
/// </summary>
3636
public event InAppNotificationClosedEventHandler Closed;
3737

38-
private AutomationPeer peer;
39-
4038
private void DismissButton_Click(object sender, RoutedEventArgs e)
4139
{
4240
Dismiss(InAppNotificationDismissKind.User);
@@ -54,15 +52,18 @@ private void OpenAnimationTimer_Tick(object sender, object e)
5452
_openAnimationTimer.Stop();
5553
Opened?.Invoke(this, EventArgs.Empty);
5654
SetValue(AutomationProperties.NameProperty, StringExtensions.GetLocalized("WindowsCommunityToolkit_InAppNotification_NameProperty", "/Microsoft.Toolkit.Uwp.UI.Controls/Resources"));
57-
peer = FrameworkElementAutomationPeer.CreatePeerForElement(ContentTemplateRoot);
58-
if (Content?.GetType() == typeof(string))
55+
if (ContentTemplateRoot != null)
5956
{
60-
AutomateTextNotification(Content.ToString());
57+
var peer = FrameworkElementAutomationPeer.CreatePeerForElement(ContentTemplateRoot);
58+
if (Content?.GetType() == typeof(string))
59+
{
60+
AutomateTextNotification(peer, Content.ToString());
61+
}
6162
}
6263
}
6364
}
6465

65-
private void AutomateTextNotification(string message)
66+
private void AutomateTextNotification(AutomationPeer peer, string message)
6667
{
6768
if (peer != null)
6869
{

0 commit comments

Comments
 (0)