c# - 在 Xamarin Forms 中通过 App.xaml.cs 动画打开 MainPage

标签 c# xamarin xamarin.forms

在 Xamarin Forms 中推送页面时,我可以通过将 animate 属性设置为 true 轻松地为其设置动画

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

在 App() 构造函数中从 App.xaml.cs 打开 MainPage 时如何实现相同的目的?我将 MainPage 视为 .Animate 扩展,但我没有找到任何关于如何使用它的合适示例。

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

更新

我发现这段代码放在 OnAppearing 的覆盖中,我可以看到它应该做什么,但它实际上什么也没做,有人能看出为什么吗?

this.Animate("", (s) => Layout(new Rectangle(X, (1 - s) * Height, Width, Height)), 0, 600, Easing.SpringIn, null, null);

最佳答案

您必须设置一个超时时间才能使动画生效。 OnAppearingPage 实际出现之前被多次调用。在超时中插入动画,就像这样......

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

成为 BounceUp 您的动画 Storyboard。

更新:您还必须在 OnAppearing 方法中使用修饰符 async

关于c# - 在 Xamarin Forms 中通过 App.xaml.cs 动画打开 MainPage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48924191/

相关文章:

c# - 在 ListView 控件中获取鼠标光标下的项目?

c# - 将 DialogViewController 推送到 ViewController 到 NavigationController 堆栈上会产生 2 页

c# - map 服务器: anyplatfom (opensource or not) to embed into website to query with SQL for further breakdown

xamarin - Xamarin IOS 模拟器是否需要 XCode?

ios - 无法在 Visual Studio 2013 for Xamarin Projects 中从 iPhone 切换到 iPhoneSimulator

c# - ListView 不随分组滚动

c# - 枚举所有 "always on top"的窗口

sockets - 在Xamarin for Windows Phone中使用Windows.Networking.Sockets

android - 在选择输入控件之前,Xamarin.Forms 开关控件在 Android 上不可见

entity-framework - iOS 上使用 Entity Framework Core 和 Xamarin Forms 的 PlatformNotSupportedException