0

I have tried to different methods to get my MainPage to change and it is not happening. Basically when my App starts it needs to do some Async tasks to initialize everything, and then get the real main page to display. I first tried an event handler in App.cs. I can confirm the event handler does fire off in my debugger. However the code to switch the main page is not successfully doing so. Nothing changes in my UI. This code is below:

    private void UnitStatusModelChanged(object sender, EventArgs e)
    {
        UnitStatusModel = _unitStatusMonitor.UnitStatusModel;
        UnitStatusViewModel = new UnitStatusViewModel(UnitStatusModel, InputResourceHandler);
        MainPage = new MainTabbed(UnitStatusViewModel, InputResourceHandler);
        Debug.WriteLine("Switched page to " + UnitStatusModel.Version.Name);
    }

    protected override void OnStart()
    {
        _unitStatusMonitor.UnitStatusChanged += new UnitStatusModelChangedEventHandler(UnitStatusModelChanged);
        _commandQueue.StartQueue();
    }

I thought maybe setting MainPage this way is not the way to go. So I tried making the MainPage a blank NavigationPage, and then pushing a model page on top once the app is ready. This also had no effect.

            var newPage = new MainTabbed(
                new UnitStatusViewModel(_unitStatusModel, inputResourceHandler),
                inputResourceHandler
                );
            App.Current.MainPage.Navigation.PushModalAsync(newPage);

I can confirm that if I start the app with a MainTabbed page, the page does display, so it should not be a problem with MainTabbed. Again, I also verified the in the debugger these lines of code are being executed with no exceptions being thrown. Still, no change to MainPage. What gives?

1
  • Please share your full code in Application class
    – Sreeraj
    Apr 27, 2016 at 2:18

1 Answer 1

1

Check your thread after your async completes, when you call PushModalAsync (or any UI thing). Make sure it's on the main thread.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.