From af6ac9649f71d1557dffa3dc3357868016ebc1e7 Mon Sep 17 00:00:00 2001 From: Samantha Houts Date: Thu, 16 Jun 2016 10:09:22 -0700 Subject: [PATCH] [UWP] MasterDetailControl will no longer null out the TCS before it is used. (#227) * [UWP] Don't null the _commandBarTcs too soon * Add repro for 41842 --- .../Bugzilla41842.cs | 35 ++++++++++++++++++++++ .../Xamarin.Forms.Controls.Issues.Shared.projitems | 1 + Xamarin.Forms.Platform.UAP/MasterDetailControl.cs | 14 ++++----- 3 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41842.cs diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41842.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41842.cs new file mode 100644 index 0000000..f571423 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41842.cs @@ -0,0 +1,35 @@ +using System; + +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; + +#if UITEST +using Xamarin.UITest; +using NUnit.Framework; +#endif + +namespace Xamarin.Forms.Controls +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Bugzilla, 41842, "Set MasterDetailPage.Detail = New Page() twice will crash the application when set MasterBehavior = MasterBehavior.Split", PlatformAffected.WinRT)] + public class Bugzilla41842 : TestMasterDetailPage + { + protected override void Init() + { + MasterBehavior = MasterBehavior.Split; + + Master = new Page() { Title = "Master" }; + + Detail = new NavigationPage(new Page()); + Detail = new NavigationPage(new ContentPage { Content = new Label { Text = "Success" } }); + } + +#if UITEST + [Test] + public void Bugzilla41842Test() + { + RunningApp.WaitForElement(q => q.Marked("Success")); + } +#endif + } +} 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 5c96324..1e9d1ea 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 @@ -153,6 +153,7 @@ + diff --git a/Xamarin.Forms.Platform.UAP/MasterDetailControl.cs b/Xamarin.Forms.Platform.UAP/MasterDetailControl.cs index 9ec03f8..6787cce 100644 --- a/Xamarin.Forms.Platform.UAP/MasterDetailControl.cs +++ b/Xamarin.Forms.Platform.UAP/MasterDetailControl.cs @@ -167,7 +167,11 @@ namespace Xamarin.Forms.Platform.UWP _commandBarTcs = new TaskCompletionSource(); ApplyTemplate(); - return _commandBarTcs.Task; + + var commandBarFromTemplate = _commandBarTcs.Task; + _commandBarTcs = null; + + return commandBarFromTemplate; } protected override void OnApplyTemplate() @@ -193,12 +197,8 @@ namespace Xamarin.Forms.Platform.UWP UpdateMode(); - TaskCompletionSource tcs = _commandBarTcs; - if (tcs != null) - { - _commandBarTcs = null; - tcs.SetResult(_commandBar); - } + if (_commandBarTcs != null) + _commandBarTcs.SetResult(_commandBar); } static void OnShouldShowSplitModeChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) -- 2.7.4