xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.63k stars 1.88k forks source link

[Bug] [UWP] - When calling Navigation.PopAsync inside MasterDetailPage the OnDisappearing is not called #10413

Open BrayanKhosravian opened 4 years ago

BrayanKhosravian commented 4 years ago

Description

Steps to Reproduce

  1. clone this repro: https://github.com/Xamarin-Forms-Issues-Repro/MasterDetailUwpOnDisappearing
  2. set UWP as startup project
  3. set a breakpoint in MasterDetailUwpOnDisappearing.Views.MainPage.OnDisappearing
  4. debug the app
  5. press the buttton on the first page with the title "Navigate to master detail"
  6. on the master page press the red button with the title "navigate back!" => OnDisappearing is not called on UWP

Expected Behavior

OnDisappearing should be called when popping the master detail page from the navigationstack like it is called on android

Actual Behavior

OnDisappearing is not called when popping the masterdetail page from the navigations tack on uwp

Basic Information

Screenshots

Reproduction Link

https://github.com/Xamarin-Forms-Issues-Repro/MasterDetailUwpOnDisappearing

Workaround

none

BrayanKhosravian commented 4 years ago

the same applies to modal navigation

BrayanKhosravian commented 4 years ago

FYI @bruzkovsky @gentledepp

BrayanKhosravian commented 4 years ago

i think this issue can be resolved by calling Element.OnDisappearing() in the Xamarin.Forms.Platform.UWP.MasterDetailPageRenderer.Dispose method

public void Dispose()
        {
            ClearMaster();
            ClearDetail();

            Tracker = null;
            if (Element != null)
            {
                Element.SendDisappearing();  // <= Add this
                SetElement(null);
            }
        }

@gentledepp found that out after a search

BrayanKhosravian commented 4 years ago

here is the branch i was working on: https://github.com/BrayanKhosravian/Xamarin.Forms/tree/bug-uwp-10413-ondisappearing-notcalled-after-popasync-in-masterdetail

i already created an issue in the control gallery. you could just pick my commit if that helps. Wasnt able to push the branch to upstream as i dont have premissions.