DarkW1nter
DarkW1nter

Reputation: 2851

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);

Upvotes: 4

Views: 1123

Answers (1)

Greggz
Greggz

Reputation: 1799

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

Upvotes: 8

Related Questions