1

当用户在我的应用程序中移动页面时,简单的动画应该在移动之前淡出项目,但它不起作用并且立即进行切换。

代码:

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

现在,这不起作用,它会立即回到 MainPage,有人知道吗?

4

1 回答 1

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
}
于 2012-10-22T18:41:37.897 回答