当用户在我的应用程序中移动页面时,简单的动画应该在移动之前淡出项目,但它不起作用并立即进行移位。
代码:
public PageClass()
{
BackKeyPress += OnBackKeyPressed;
}
void OnBackKeyPressed(object sender, CancelEventArgs e)
{
foreach (var control in ContentPanel.Children)
MainPage.FadeOutObject(control);
var translation = new TranslateTransform();
PageTitle.RenderTransform = translation;
var s = new Storyboard();
Storyboard.SetTarget(s, translation);
Storyboard.SetTargetProperty(s, new PropertyPath(TranslateTransform.YProperty));
s.Children.Add(
new DoubleAnimation()
{
From = -300,
To = 0,
Duration = new Duration(TimeSpan.FromSeconds(2.0)),
EasingFunction = new PowerEase { EasingMode = EasingMode.EaseInOut }
});
s.Begin();
s.Completed += (object sd, EventArgs ea) =>
{
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
};
}
现在,这不起作用,它会立即回到主页,是否有人有线索?
答案 0 :(得分:3)
尝试添加e.Cancel
以停止自动处理上一页,因为您已经告诉它应该去哪个页面。
void OnBackKeyPressed(object sender, CancelEventArgs e)
{
e.Cancel = true;
foreach (var control in ContentPanel.Children)
MainPage.FadeOutObject(control);
//...rest of your code
}