0

In my app I am using OnNavigatingFrom and OnNavigatedTo events to modify state of my view, for instance reset state of view to initial. This causes problems with navigation - when user clicks button, he sees blink of page in initial state, when it is doing its leaving animation. How I should code my UI to deal with this?

Page flow:

  1. OnNavigatingTo is called
  2. User does job on page
  3. User clicks button to navigate away
  4. OnNavigatingFrom is called
  5. Page resets UI to initial state
  6. ContentFrame starts to play output animation (user sees briefly page 1. state)
  7. ContentFrame switches to new page

Repro: https://github.com/ShadowDancer/uwp.transitions.repro.git

Shadow
  • 2,089
  • 2
  • 23
  • 45

1 Answers1

1

In UWP, page transitions have connection animations by default. If this connection animation is bothering you, you can try to modify it.

myFrame.Navigate(typeof(Page2), null, new SuppressNavigationTransitionInfo());

If you want to learn more about page connect animation, check out this document: Page transitions.


Update

I checked your project code. In OnNavigatingFrom, you reset the page state, which caused the state to change during the page connection animation.

Functionally, I suggest that you write the code to rewrite the page state in the OnNavigatedTo event, to rewrite the page state each time you navigate to the page, without having to listen to the OnNavigatingFrom event.

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    SetState(false);
    base.OnNavigatedTo(e);
}

Update

There is another method, which is to delay the state change. Switch state after ensuring page animation is complete

protected async override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
    await Task.Delay(500);
    SetState(false);
    base.OnNavigatingFrom(e);
}
Richard Zhang
  • 7,523
  • 1
  • 7
  • 13
  • I would like to keep page transitions, it is nice visual effect. Just I wonder what is correct way to reset state without jumping elements during animation. – Shadow Mar 10 '20 at 06:16
  • Can you provide a minimum runnable demo so that I can reproduce your problem? – Richard Zhang Mar 10 '20 at 06:27
  • I have added repro to question. – Shadow Mar 11 '20 at 08:21
  • It does not solve the problem, because then it blinks when I am navigating to page (in case "state" is held by model and not in page class). – Shadow Mar 11 '20 at 08:57
  • The essence of this problem is the conflict between the time of page switching animation and the display of status. There is another way, I modified the answer again. – Richard Zhang Mar 11 '20 at 09:08