简体   繁体   English

在Xamarin Forms中从App.xaml.cs动画打开MainPage

[英]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 在Xamarin Forms中推送页面时,我可以通过将animate属性设置为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? 在App()构造函数中从App.xaml.cs打开MainPage时,如何实现相同的功能? I see MainPage as a .Animate extension but I've not found any decent examples of how to use it. 我看到MainPage是一个.Animate扩展,但我没有找到任何关于如何使用它的体面示例。

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

UPDATE 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? 我发现这个代码放在OnAppearing的覆盖中,我可以看到它该做什么,但实际上并没有做任何事情,任何人都可以看到原因吗?

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. Page实际出现之前, OnAppearing被称为很多时间。 Insert your animation in a timeout, like this.. 在超时中插入动画,如下所示..

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

Being BounceUp your animation story board. BounceUp你的动画故事板。

Update: You must also use the modifier async in OnAppearing method 更新:您还必须在OnAppearing方法中使用修饰符async

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将参数从 app.xaml.cs 传递到 MainPage - Pass parameter from app.xaml.cs to MainPage 从Windows Phone 8中的App.Xaml.cs到达MainPage.Xaml.cs单击处理程序函数 - Reaching MainPage.Xaml.cs click handler functions from App.Xaml.cs in windows phone 8 如何从App.xaml.cs调用MainPage.xaml.cs中的函数 - How to call a function that's in MainPage.xaml.cs from App.xaml.cs App.xaml.cs 中的 Xamarin 表单更新值 - Xamarin Forms Update value in App.xaml.cs 如何从 App.xaml 而不是 App.xaml.cs 设置 MainPage? - How to set MainPage from App.xaml instead of App.xaml.cs? 如何在app.xaml.cs中使用具有可变appbar枢轴的MainPage中的方法 - How to use a method in MainPage from app.xaml.cs with variable appbar pivot 在 UWP 应用程序中,读取命令行 arguments 并将其从 App.xaml.cs 文件传递到 MainPage.Z44CC44B81911F4BA4581C27 - In UWP App, read command line arguments and pass it from App.xaml.cs file to the MainPage.xaml.cs App.Xaml.cs和MainPage.xaml.cs不能包含在Visual Studio Community 2017的解决方案资源管理器中 - App.Xaml.cs and MainPage.xaml.cs cannot be included in Solutions Explorer of Visual Studio Community 2017 如何处理 xamarin.forms 中 app.xaml.cs 中的 System.TypeLoadException? - How to deal with System.TypeLoadException in the app.xaml.cs in xamarin.forms? 从App.xaml.cs导航 - Navigating from App.xaml.cs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM