Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animate the opening of MainPage from App.xaml.cs in Xamarin Forms

When pushing a page in Xamarin Forms I can animate it easily by setting the animate property to true

await Navigation.PushModalAsync(NavigationPageHelper.Create(new MyPage(), true);

How can I achieve the same thing when opening the MainPage from App.xaml.cs, in the App() constructor? I see MainPage as a .Animate extension but I've not found any decent examples of how to use it.

InitializeComponent();
MainPage = GetMainPage(); // GetMainPage returns the correct page to open
MainPage.SetValue(NavigationPage.BarTextColorProperty, Color.White);

UPDATE

I found this code to place in the override of OnAppearing, I can see what it should be doing but it doesn't actually do anything, Can anyone see why?

this.Animate("", (s) => Layout(new Rectangle(X, (1 - s) * Height, Width, Height)), 0, 600, Easing.SpringIn, null, null);
like image 567
DarkW1nter Avatar asked Jan 29 '23 15:01

DarkW1nter


1 Answers

You must set a timeout for the animation to take effect. OnAppearing is called a lot of time before the Page actually appears. Insert your animation in a timeout, like this..

Task.Delay(1000).ContinueWith(t => BounceUp());

Being BounceUp your animation story board.

Update: You must also use the modifier async in OnAppearing method

like image 94
Greggz Avatar answered Jan 31 '23 04:01

Greggz