@@ -14,8 +14,6 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
1414{
1515 public sealed partial class InAppNotificationPage : Page , IXamlRenderListener
1616 {
17- private ControlTemplate _defaultInAppNotificationControlTemplate ;
18- private ControlTemplate _customInAppNotificationControlTemplate ;
1917 private InAppNotification _exampleInAppNotification ;
2018 private InAppNotification _exampleCustomInAppNotification ;
2119 private InAppNotification _exampleVSCodeInAppNotification ;
@@ -36,9 +34,7 @@ public void OnXamlRendered(FrameworkElement control)
3634 NotificationDuration = 0 ;
3735
3836 _exampleInAppNotification = control . FindChild ( "ExampleInAppNotification" ) as InAppNotification ;
39- _defaultInAppNotificationControlTemplate = _exampleInAppNotification ? . Template ;
4037 _exampleCustomInAppNotification = control . FindChild ( "ExampleCustomInAppNotification" ) as InAppNotification ;
41- _customInAppNotificationControlTemplate = _exampleCustomInAppNotification ? . Template ;
4238 _exampleVSCodeInAppNotification = control . FindChild ( "ExampleVSCodeInAppNotification" ) as InAppNotification ;
4339 _resources = control . Resources ;
4440
@@ -53,24 +49,24 @@ private void Load()
5349 {
5450 SampleController . Current . RegisterNewCommand ( "Show notification with random text" , ( sender , args ) =>
5551 {
56- _exampleVSCodeInAppNotification ? . Dismiss ( ) ;
57- SetDefaultControlTemplate ( ) ;
52+ _exampleVSCodeInAppNotification . Dismiss ( true ) ;
53+ _exampleCustomInAppNotification . Dismiss ( true ) ;
5854 _exampleInAppNotification ? . Show ( GetRandomText ( ) , NotificationDuration ) ;
5955 } ) ;
6056
6157 SampleController . Current . RegisterNewCommand ( "Show notification with object" , ( sender , args ) =>
6258 {
63- _exampleVSCodeInAppNotification ? . Dismiss ( ) ;
64- SetDefaultControlTemplate ( ) ;
59+ _exampleVSCodeInAppNotification . Dismiss ( true ) ;
60+ _exampleCustomInAppNotification . Dismiss ( true ) ;
6561
6662 var random = new Random ( ) ;
6763 _exampleInAppNotification ? . Show ( new KeyValuePair < int , string > ( random . Next ( 1 , 10 ) , GetRandomText ( ) ) , NotificationDuration ) ;
6864 } ) ;
6965
7066 SampleController . Current . RegisterNewCommand ( "Show notification with buttons (without DataTemplate)" , ( sender , args ) =>
7167 {
72- _exampleVSCodeInAppNotification ? . Dismiss ( ) ;
73- SetDefaultControlTemplate ( ) ;
68+ _exampleVSCodeInAppNotification . Dismiss ( true ) ;
69+ _exampleCustomInAppNotification . Dismiss ( true ) ;
7470
7571 var grid = new Grid ( )
7672 {
@@ -126,46 +122,30 @@ private void Load()
126122
127123 SampleController . Current . RegisterNewCommand ( "Show notification with buttons (with DataTemplate)" , ( sender , args ) =>
128124 {
129- _exampleVSCodeInAppNotification ? . Dismiss ( ) ;
130- SetCustomControlTemplate ( ) ; // Use the custom template without the Dismiss button. The DataTemplate will handle re-adding it.
125+ _exampleVSCodeInAppNotification . Dismiss ( true ) ;
126+ _exampleInAppNotification . Dismiss ( true ) ;
131127
132- object inAppNotificationWithButtonsTemplate = null ;
133- bool ? isTemplatePresent = _resources ? . TryGetValue ( "InAppNotificationWithButtonsTemplate" , out inAppNotificationWithButtonsTemplate ) ;
134-
135- if ( isTemplatePresent == true && inAppNotificationWithButtonsTemplate is DataTemplate template )
128+ object inAppNotificationWithButtonsTemplateResource = null ;
129+ bool ? isTemplatePresent = _resources ? . TryGetValue ( "InAppNotificationWithButtonsTemplate" , out inAppNotificationWithButtonsTemplateResource ) ;
130+ if ( isTemplatePresent == true && inAppNotificationWithButtonsTemplateResource is DataTemplate inAppNotificationWithButtonsTemplate )
136131 {
137- _exampleInAppNotification . Show ( template , NotificationDuration ) ;
132+ _exampleCustomInAppNotification . Show ( inAppNotificationWithButtonsTemplate , NotificationDuration ) ;
138133 }
139134 } ) ;
140135
141- SampleController . Current . RegisterNewCommand ( "Show notification with Drop Shadow (based on default template)" , ( sender , args ) =>
142- {
143- _exampleVSCodeInAppNotification . Dismiss ( ) ;
144- SetDefaultControlTemplate ( ) ;
145-
146- // Update control template
147- object inAppNotificationDropShadowControlTemplate = null ;
148- bool ? isTemplatePresent = _resources ? . TryGetValue ( "InAppNotificationDropShadowControlTemplate" , out inAppNotificationDropShadowControlTemplate ) ;
149-
150- if ( isTemplatePresent == true && inAppNotificationDropShadowControlTemplate is ControlTemplate template )
151- {
152- _exampleInAppNotification . Template = template ;
153- }
154-
155- _exampleInAppNotification . Show ( GetRandomText ( ) , NotificationDuration ) ;
156- } ) ;
157-
158136 SampleController . Current . RegisterNewCommand ( "Show notification with Visual Studio Code template (info notification)" , ( sender , args ) =>
159137 {
160- _exampleInAppNotification . Dismiss ( ) ;
138+ _exampleInAppNotification . Dismiss ( true ) ;
139+ _exampleCustomInAppNotification . Dismiss ( true ) ;
161140 _exampleVSCodeInAppNotification . Show ( NotificationDuration ) ;
162141 } ) ;
163142
164143 SampleController . Current . RegisterNewCommand ( "Dismiss" , ( sender , args ) =>
165144 {
166145 // Dismiss all notifications (should not be replicated in production)
167- _exampleInAppNotification . Dismiss ( ) ;
168- _exampleVSCodeInAppNotification . Dismiss ( ) ;
146+ _exampleInAppNotification . Dismiss ( true ) ;
147+ _exampleCustomInAppNotification . Dismiss ( true ) ;
148+ _exampleVSCodeInAppNotification . Dismiss ( true ) ;
169149 } ) ;
170150 }
171151
@@ -182,18 +162,6 @@ private string GetRandomText()
182162 }
183163 }
184164
185- private void SetDefaultControlTemplate ( )
186- {
187- // Update control template
188- _exampleInAppNotification . Template = _defaultInAppNotificationControlTemplate ;
189- }
190-
191- private void SetCustomControlTemplate ( )
192- {
193- // Update control template
194- _exampleInAppNotification . Template = _customInAppNotificationControlTemplate ;
195- }
196-
197165 private void NotificationDurationTextBox_TextChanged ( object sender , TextChangedEventArgs e )
198166 {
199167 int newDuration ;
0 commit comments