在 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);
最佳答案
您必须设置一个超时时间才能使动画生效。 OnAppearing
在 Page
实际出现之前被多次调用。在超时中插入动画,就像这样......
Task.Delay(1000).ContinueWith(t => BounceUp());
成为 BounceUp
您的动画 Storyboard。
更新:您还必须在 OnAppearing
方法中使用修饰符 async
关于c# - 在 Xamarin Forms 中通过 App.xaml.cs 动画打开 MainPage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48924191/