简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM