|
| 1 | +namespace Maui.Controls.Sample.Issues; |
| 2 | + |
| 3 | +[XamlCompilation(XamlCompilationOptions.Compile)] |
| 4 | +[Issue(IssueTracker.Github, 29923, "Removed page handlers not disconnected when using Navigation.RemovePage()", PlatformAffected.All)] |
| 5 | +public partial class Issue29923 : Shell |
| 6 | +{ |
| 7 | + public Issue29923() |
| 8 | + { |
| 9 | + var rootPage = new ContentPage |
| 10 | + { |
| 11 | + Title = "Handler Disconnection Test", |
| 12 | + Content = new VerticalStackLayout |
| 13 | + { |
| 14 | + Padding = new Thickness(30, 0), |
| 15 | + Spacing = 25, |
| 16 | + Children = |
| 17 | + { |
| 18 | + new Button |
| 19 | + { |
| 20 | + Text = "Test Page Modal", |
| 21 | + AutomationId = "NavigateToTestPageModalButton", |
| 22 | + Command = new Command(async () => |
| 23 | + { |
| 24 | + var navPage = new NavigationPage(); |
| 25 | + var page1 = new Issue29923TestPage(); |
| 26 | + var page2 = new Issue29923TestPage2(); |
| 27 | + |
| 28 | + await navPage.PushAsync(page1); |
| 29 | + await navPage.PushAsync(page2); |
| 30 | + |
| 31 | + await Navigation.PushModalAsync(navPage); |
| 32 | + }) |
| 33 | + }, |
| 34 | + new Button |
| 35 | + { |
| 36 | + Text = "Test Page", |
| 37 | + AutomationId = "NavigateToTestPageButton", |
| 38 | + Command = new Command(async () => |
| 39 | + { |
| 40 | + var page1 = new Issue29923TestPage(); |
| 41 | + var page2 = new Issue29923TestPage2(); |
| 42 | + |
| 43 | + await Navigation.PushAsync(page1); |
| 44 | + await Navigation.PushAsync(page2); |
| 45 | + }) |
| 46 | + } |
| 47 | + } |
| 48 | + } |
| 49 | + }; |
| 50 | + |
| 51 | + Items.Add(new ShellContent |
| 52 | + { |
| 53 | + Title = "Handler Test", |
| 54 | + Content = rootPage |
| 55 | + }); |
| 56 | + } |
| 57 | + |
| 58 | + public class Issue29923TestPage : ContentPage |
| 59 | + { |
| 60 | + public Issue29923TestPage() |
| 61 | + { |
| 62 | + Title = "Test Page"; |
| 63 | + |
| 64 | + Content = new VerticalStackLayout |
| 65 | + { |
| 66 | + Padding = new Thickness(20), |
| 67 | + Spacing = 10, |
| 68 | + }; |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + public class Issue29923TestPage2 : ContentPage |
| 73 | + { |
| 74 | + private Label _handlerStatusLabel; |
| 75 | + |
| 76 | + public Issue29923TestPage2() |
| 77 | + { |
| 78 | + Title = "Test Page 2"; |
| 79 | + |
| 80 | + _handlerStatusLabel = new Label |
| 81 | + { |
| 82 | + Text = "", |
| 83 | + AutomationId = "HandlerStatusLabel", |
| 84 | + FontAttributes = FontAttributes.Bold |
| 85 | + }; |
| 86 | + |
| 87 | + Content = new VerticalStackLayout |
| 88 | + { |
| 89 | + Padding = new Thickness(20), |
| 90 | + Spacing = 10, |
| 91 | + Children = |
| 92 | + { |
| 93 | + new Label |
| 94 | + { |
| 95 | + Text = "Test Page Removal Scenarios", |
| 96 | + FontSize = 18, |
| 97 | + FontAttributes = FontAttributes.Bold |
| 98 | + }, |
| 99 | + new Button |
| 100 | + { |
| 101 | + Text = "Remove Test Page 1", |
| 102 | + AutomationId = "RemoveTestPage1Button", |
| 103 | + Command = new Command(RemoveFirstPage) |
| 104 | + }, |
| 105 | + new Button |
| 106 | + { |
| 107 | + Text = "Pop Modal", |
| 108 | + AutomationId = "PopModalButton", |
| 109 | + Command = new Command(() => Navigation.PopModalAsync()) |
| 110 | + }, |
| 111 | + new HorizontalStackLayout |
| 112 | + { |
| 113 | + Children = |
| 114 | + { |
| 115 | + new Label { Text = "Is Handler still available:", FontAttributes = FontAttributes.Bold }, |
| 116 | + _handlerStatusLabel |
| 117 | + } |
| 118 | + } |
| 119 | + } |
| 120 | + }; |
| 121 | + } |
| 122 | + |
| 123 | + private void RemoveFirstPage() |
| 124 | + { |
| 125 | + var navigationStack = Navigation.NavigationStack; |
| 126 | + if (navigationStack.Count == 0) |
| 127 | + return; |
| 128 | + |
| 129 | + var pageToRemove = navigationStack.FirstOrDefault(); |
| 130 | + if (pageToRemove == null && navigationStack.Count > 1) |
| 131 | + pageToRemove = navigationStack[1]; |
| 132 | + |
| 133 | + if (pageToRemove != null) |
| 134 | + { |
| 135 | + Navigation.RemovePage(pageToRemove); |
| 136 | + _handlerStatusLabel.Text = (pageToRemove.Handler != null).ToString(); |
| 137 | + } |
| 138 | + } |
| 139 | + } |
| 140 | +} |
0 commit comments