@@ -35,6 +35,19 @@ public partial class InAppNotification
35
35
/// </summary>
36
36
public event InAppNotificationClosedEventHandler Closed ;
37
37
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
+
38
51
private void DismissButton_Click ( object sender , RoutedEventArgs e )
39
52
{
40
53
Dismiss ( InAppNotificationDismissKind . User ) ;
@@ -45,44 +58,37 @@ private void DismissTimer_Tick(object sender, object e)
45
58
Dismiss ( InAppNotificationDismissKind . Timeout ) ;
46
59
}
47
60
48
- private void OpenAnimationTimer_Tick ( object sender , object e )
61
+ private void OnCurrentStateChanged ( object sender , VisualStateChangedEventArgs e )
49
62
{
50
- lock ( _openAnimationTimer )
63
+ switch ( e . NewState . Name )
51
64
{
52
- _openAnimationTimer . Stop ( ) ;
53
- Opened ? . Invoke ( this , EventArgs . Empty ) ;
54
- SetValue ( AutomationProperties . NameProperty , StringExtensions . GetLocalized ( "WindowsCommunityToolkit_InAppNotification_NameProperty" , "/Microsoft.Toolkit.Uwp.UI.Controls/Resources" ) ) ;
55
- if ( ContentTemplateRoot != null )
56
- {
57
- var peer = FrameworkElementAutomationPeer . CreatePeerForElement ( ContentTemplateRoot ) ;
58
- if ( Content ? . GetType ( ) == typeof ( string ) )
59
- {
60
- AutomateTextNotification ( peer , Content . ToString ( ) ) ;
61
- }
62
- }
65
+ case StateContentVisible :
66
+ OnNotificationVisible ( ) ;
67
+ break ;
68
+ case StateContentCollapsed :
69
+ OnNotificationCollapsed ( ) ;
70
+ break ;
63
71
}
64
72
}
65
73
66
- private void AutomateTextNotification ( AutomationPeer peer , string message )
74
+ private void OnNotificationVisible ( )
67
75
{
68
- if ( peer != null )
76
+ Opened ? . Invoke ( this , EventArgs . Empty ) ;
77
+ SetValue ( AutomationProperties . NameProperty , StringExtensions . GetLocalized ( "WindowsCommunityToolkit_InAppNotification_NameProperty" , "/Microsoft.Toolkit.Uwp.UI.Controls/Resources" ) ) ;
78
+ if ( ContentTemplateRoot != null )
69
79
{
70
- peer . SetFocus ( ) ;
71
- peer . RaiseNotificationEvent (
72
- AutomationNotificationKind . Other ,
73
- AutomationNotificationProcessing . ImportantMostRecent ,
74
- StringExtensions . GetLocalized ( "WindowsCommunityToolkit_InAppNotification_Events_NewNotificationMessage" , "/Microsoft.Toolkit.Uwp.UI.Controls/Resources" ) + message ,
75
- Guid . NewGuid ( ) . ToString ( ) ) ;
80
+ var peer = FrameworkElementAutomationPeer . CreatePeerForElement ( ContentTemplateRoot ) ;
81
+ if ( Content ? . GetType ( ) == typeof ( string ) )
82
+ {
83
+ AutomateTextNotification ( peer , Content . ToString ( ) ) ;
84
+ }
76
85
}
77
86
}
78
87
79
- private void ClosingAnimationTimer_Tick ( object sender , object e )
88
+ private void OnNotificationCollapsed ( )
80
89
{
81
- lock ( _closingAnimationTimer )
82
- {
83
- _closingAnimationTimer . Stop ( ) ;
84
- Closed ? . Invoke ( this , new InAppNotificationClosedEventArgs ( _lastDismissKind ) ) ;
85
- }
90
+ Closed ? . Invoke ( this , new InAppNotificationClosedEventArgs ( _lastDismissKind ) ) ;
91
+ Visibility = Visibility . Collapsed ;
86
92
}
87
93
}
88
94
}
0 commit comments