[Bug] NullReferenceException Closing Window During Animation (#7067)
authorGerald Versluis <gerald.versluis@microsoft.com>
Fri, 9 Aug 2019 00:51:06 +0000 (02:51 +0200)
committerSamantha Houts <samhouts@users.noreply.github.com>
Fri, 9 Aug 2019 00:51:06 +0000 (17:51 -0700)
* Added null check to current application for WPF

* Apply suggestions from code review

Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com>
fixes #7061

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7061.cs [new file with mode: 0644]
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
Xamarin.Forms.Platform.WPF/WPFPlatformServices.cs

diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7061.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7061.cs
new file mode 100644 (file)
index 0000000..5b06eaf
--- /dev/null
@@ -0,0 +1,37 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+
+namespace Xamarin.Forms.Controls.Issues
+{
+       [Preserve(AllMembers = true)]
+       [Issue(IssueTracker.Github, 7061, "[Bug] NullReferenceException Closing Window During Animation", PlatformAffected.UWP)]
+       public class Issue7061 : TestContentPage
+       {
+               Label _animatedLabel = new Label { Text = "Scaling out" };
+               Label _explanationLabel = new Label { Text = "When you close the app while the animation is still running you should not get an exception" };
+
+               protected override void Init()
+               {
+                       var stack = new StackLayout
+                       {
+                               HorizontalOptions = LayoutOptions.Center,
+                               VerticalOptions = LayoutOptions.Center
+                       };
+
+                       stack.Children.Add(_explanationLabel);
+                       stack.Children.Add(_animatedLabel);
+
+                       Content = stack;
+               }
+
+               protected override void OnAppearing()
+               {
+                       base.OnAppearing();
+
+                       _animatedLabel.ScaleTo(10, length: (uint)TimeSpan.FromMinutes(1).TotalMilliseconds);
+               }
+       }
+}
index b80806b..1ac48fb 100644 (file)
@@ -21,6 +21,7 @@
     <Compile Include="$(MSBuildThisFileDirectory)Issue6644.xaml.cs">
       <SubType>Code</SubType>
     </Compile>
+    <Compile Include="$(MSBuildThisFileDirectory)Issue7061.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)ShellGestures.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)ShellInsets.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)CollectionViewGrouping.cs" />
index 8978807..ae53ab8 100644 (file)
@@ -30,7 +30,7 @@ namespace Xamarin.Forms.Platform.WPF
                
                public void BeginInvokeOnMainThread(Action action)
                {
-                       System.Windows.Application.Current.Dispatcher.BeginInvoke(action);
+                       System.Windows.Application.Current?.Dispatcher.BeginInvoke(action);
                }
 
                public Ticker CreateTicker()