[8.1/UWP] Fix PopToRootAsync functioning incorrectly (#185)
authorPaul DiPietro <paul.dipietro@me.com>
Thu, 26 May 2016 19:14:56 +0000 (15:14 -0400)
committerkingces95 <kingces95@users.noreply.github.com>
Thu, 26 May 2016 19:14:56 +0000 (12:14 -0700)
When using PopToRootAsync on 8.1/UWP, the stack was being cleared but
the actual page was not being set due to a missing event handler on the
NavigationPageRenderer.

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla31806.cs [new file with mode: 0644]
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
Xamarin.Forms.Platform.WinRT/NavigationPageRenderer.cs

diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla31806.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla31806.cs
new file mode 100644 (file)
index 0000000..60c68a0
--- /dev/null
@@ -0,0 +1,55 @@
+using System;
+
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+
+#if UITEST
+using Xamarin.UITest;
+using NUnit.Framework;
+#endif
+
+namespace Xamarin.Forms.Controls.Issues
+{
+       [Preserve(AllMembers = true)]
+       [Issue(IssueTracker.Bugzilla, 31806, "[8.1/UWP] PopToRootAsync crashes due to not setting the current page correctly", PlatformAffected.WinRT)]
+       public class Bugzilla31806 : TestContentPage
+       {
+               protected override void Init()
+               {
+                       Content = new StackLayout
+                       {
+                               Children =
+                               {
+                                       new Button
+                                       {
+                                               Text = "Navigate to a new page",
+                                               Command = new Command(() =>
+                                               {
+                                                       Navigation.PushAsync(new ContentPage
+                                                       {
+                                                               Content = new StackLayout
+                                                               {
+                                                                       Children =
+                                                                       {
+                                                                               new Label
+                                                                               {
+                                                                                       Text = "Pressing this button should let the navigation return to the repro list"
+                                                                               },
+                                                                               new Button
+                                                                               {
+                                                                                       Text = "Call PopToRootAsync()",
+                                                                                       Command = new Command(() =>
+                                                                                       {
+                                                                                               Navigation.PopToRootAsync();
+                                                                                       })
+                                                                               }
+                                                                       }
+                                                               }
+                                                       });
+                                               })
+                                       }
+                               }
+                       };
+               }
+       }
+}
index 48ab47a..fdeb759 100644 (file)
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla39821.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla40185.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla40333.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)Bugzilla31806.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)CarouselAsync.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla34561.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla34727.cs" />
index 9fe59ba..6e8edf5 100644 (file)
@@ -157,6 +157,7 @@ namespace Xamarin.Forms.Platform.WinRT
                        {
                                ((INavigationPageController)oldElement).PushRequested -= OnPushRequested;
                                ((INavigationPageController)oldElement).PopRequested -= OnPopRequested;
+                               ((INavigationPageController)oldElement).PopToRootRequested -= OnPopToRootRequested;
                                oldElement.InternalChildren.CollectionChanged -= OnChildrenChanged;
                                oldElement.PropertyChanged -= OnElementPropertyChanged;
                        }
@@ -187,6 +188,7 @@ namespace Xamarin.Forms.Platform.WinRT
                                Element.PropertyChanged += OnElementPropertyChanged;
                                ((INavigationPageController)Element).PushRequested += OnPushRequested;
                                ((INavigationPageController)Element).PopRequested += OnPopRequested;
+                               ((INavigationPageController)Element).PopToRootRequested += OnPopToRootRequested;
                                Element.InternalChildren.CollectionChanged += OnChildrenChanged;
 
                                if (!string.IsNullOrEmpty(Element.AutomationId))
@@ -377,6 +379,11 @@ namespace Xamarin.Forms.Platform.WinRT
                        SetPage(newCurrent, e.Animated, true);
                }
 
+               void OnPopToRootRequested(object sender, NavigationRequestedEventArgs e)
+               {
+                       SetPage(e.Page, e.Animated, true);
+               }
+
                void OnPushRequested(object sender, NavigationRequestedEventArgs e)
                {
                        SetPage(e.Page, e.Animated, false);