'Xamarin Forms navigation not working as expected in debug mode

We are working on a xamarin forms app where INavigationService is used for navigating between pages. I found a strange observation that i haven't come across.

Observation 1: App is deployed in Emulator/simulator and debug mode is stopped. => Navigation is working as expected Observation 2: App is tested while running i debug mode. => Navigation to few screens not happening until user clicks randomly on screen. i.e, when user navigates from ClassA to ClassB the control(code execution) is shifted from ClassA to ClassB but UI still shows ClassA and when user clicks on screen randomly it navigates to ClassB UI ,the method in which the Navigation code is written in ClassA doesn’t end until user click on screen.

Code: Class A VM:

    private async Task ContinueToNextPageCommandAsync()
    {
        IsBusy= true;

        if (listofItems <= 0)
        {

            await DialogService.ShowAlertAsync("Warning");
          
            return;
        }
        await NavigationService.NavigateToAsync(typeof(ClassBViewModel), parameter);
        IsBusy= False;
        return;
    }

Class B VM:

 public override async Task InitializeAsync(object navigationData1, 
 object navigationData2 = null, object navigationData3 = null)
 {
     try
     {
          IsLoadingText = true;
          // Statements to be executed during class initiation
          IsLoadingText = false;
     }
 }

Note: IsBusy=False in classA doesn’t gets triggered until user clicks on screen after navigation.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source