From d75fa4fa9260496962099dcf2fae8ad30aee1349 Mon Sep 17 00:00:00 2001 From: Gerald Versluis Date: Fri, 9 Aug 2019 02:51:06 +0200 Subject: [PATCH] [Bug] NullReferenceException Closing Window During Animation (#7067) * Added null check to current application for WPF * Apply suggestions from code review Co-Authored-By: Samantha Houts fixes #7061 --- .../Issue7061.cs | 37 ++++++++++++++++++++++ .../Xamarin.Forms.Controls.Issues.Shared.projitems | 1 + Xamarin.Forms.Platform.WPF/WPFPlatformServices.cs | 2 +- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7061.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 index 0000000..5b06eaf --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7061.cs @@ -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); + } + } +} diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index b80806b..1ac48fb 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -21,6 +21,7 @@ Code + diff --git a/Xamarin.Forms.Platform.WPF/WPFPlatformServices.cs b/Xamarin.Forms.Platform.WPF/WPFPlatformServices.cs index 8978807..ae53ab8 100644 --- a/Xamarin.Forms.Platform.WPF/WPFPlatformServices.cs +++ b/Xamarin.Forms.Platform.WPF/WPFPlatformServices.cs @@ -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() -- 2.7.4