示例#1
0
        private void RunHideStoryboard(FrameworkElement element, PopUpService.AnimationTypes animation, Action completionCallback = null)
        {
            if (element == null)
            {
                return;
            }
            Storyboard storyboard = null;

            switch (animation)
            {
            case PopUpService.AnimationTypes.Slide:
                storyboard = XamlReader.Load("<Storyboard  xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"><DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=\"(UIElement.RenderTransform).(TranslateTransform.Y)\"><EasingDoubleKeyFrame KeyTime=\"0\" Value=\"0\"/>        <EasingDoubleKeyFrame KeyTime=\"0:0:0.25\" Value=\"-50\">            <EasingDoubleKeyFrame.EasingFunction>                <ExponentialEase EasingMode=\"EaseIn\" Exponent=\"6\"/>            </EasingDoubleKeyFrame.EasingFunction>        </EasingDoubleKeyFrame>    </DoubleAnimationUsingKeyFrames>    <DoubleAnimation Storyboard.TargetProperty=\"(UIElement.Opacity)\" From=\"1\" To=\"0\" Duration=\"0:0:0.25\">        <DoubleAnimation.EasingFunction>            <ExponentialEase EasingMode=\"EaseIn\" Exponent=\"6\"/>        </DoubleAnimation.EasingFunction>    </DoubleAnimation></Storyboard>") as Storyboard;
                break;

            case PopUpService.AnimationTypes.SlideInversed:
                storyboard = XamlReader.Load("<Storyboard  xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"><DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=\"(UIElement.RenderTransform).(TranslateTransform.Y)\">        <EasingDoubleKeyFrame KeyTime=\"0\" Value=\"0\"/>        <EasingDoubleKeyFrame KeyTime=\"0:0:0.35\" Value=\"800\">            <EasingDoubleKeyFrame.EasingFunction>                <ExponentialEase EasingMode=\"EaseIn\" Exponent=\"6\"/>            </EasingDoubleKeyFrame.EasingFunction>        </EasingDoubleKeyFrame>    </DoubleAnimationUsingKeyFrames></Storyboard>") as Storyboard;
                break;

            case PopUpService.AnimationTypes.SlideHorizontal:
                storyboard = XamlReader.Load("<Storyboard  xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"><DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=\"(UIElement.RenderTransform).(TranslateTransform.X)\">        <EasingDoubleKeyFrame KeyTime=\"0\" Value=\"0\"/>        <EasingDoubleKeyFrame KeyTime=\"0:0:0.25\" Value=\"150\">            <EasingDoubleKeyFrame.EasingFunction>                <ExponentialEase EasingMode=\"EaseIn\" Exponent=\"6\"/>            </EasingDoubleKeyFrame.EasingFunction>        </EasingDoubleKeyFrame>    </DoubleAnimationUsingKeyFrames>    <DoubleAnimation Storyboard.TargetProperty=\"(UIElement.Opacity)\" From=\"1\" To=\"0\" Duration=\"0:0:0.25\">        <DoubleAnimation.EasingFunction>            <ExponentialEase EasingMode=\"EaseIn\" Exponent=\"6\"/>        </DoubleAnimation.EasingFunction>    </DoubleAnimation></Storyboard>") as Storyboard;
                break;

            case PopUpService.AnimationTypes.Swivel:
                storyboard = XamlReader.Load("<Storyboard xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"><DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=\"(UIElement.Projection).(PlaneProjection.RotationX)\">        <EasingDoubleKeyFrame KeyTime=\"0\" Value=\"0\"/>        <EasingDoubleKeyFrame KeyTime=\"0:0:0.25\" Value=\"45\">            <EasingDoubleKeyFrame.EasingFunction>                <ExponentialEase EasingMode=\"EaseIn\" Exponent=\"6\"/>            </EasingDoubleKeyFrame.EasingFunction>        </EasingDoubleKeyFrame>    </DoubleAnimationUsingKeyFrames>    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=\"(UIElement.Opacity)\">        <DiscreteDoubleKeyFrame KeyTime=\"0\" Value=\"1\" />        <DiscreteDoubleKeyFrame KeyTime=\"0:0:0.267\" Value=\"0\" />    </DoubleAnimationUsingKeyFrames></Storyboard>") as Storyboard;

                PlaneProjection planeProjection = new PlaneProjection();
                planeProjection.RotationX         = 0.0;
                planeProjection.CenterOfRotationX = element.ActualHeight / 2.0;
                element.Projection = planeProjection;
                break;

            case PopUpService.AnimationTypes.Fade:
                storyboard = XamlReader.Load("<Storyboard xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"><DoubleAnimation Duration=\"0:0:0.267\" Storyboard.TargetProperty=\"(UIElement.Opacity)\" To=\"0\"/></Storyboard>") as Storyboard;
                break;
            }
            try
            {
                if (storyboard != null)
                {
                    storyboard.Completed += ((s, e) =>
                    {
                        if (completionCallback != null)
                        {
                            completionCallback();
                        }
                    });
                    foreach (Timeline t in storyboard.Children)
                    {
                        Storyboard.SetTarget(t, element);
                    }

                    storyboard.Begin();
                }
                else
                {
                    if (completionCallback != null)
                    {
                        completionCallback();
                    }
                }
            }
            catch
            {
                if (completionCallback != null)
                {
                    completionCallback();
                }
            }
        }
示例#2
0
        private void RunShowStoryboard(FrameworkElement element, PopUpService.AnimationTypes animation, Action completionCallback = null)
        {
            if (element == null)
            {
                if (completionCallback != null)
                {
                    completionCallback();
                }
            }
            else
            {
                Storyboard storyboard = null;
                switch (animation)
                {
                case PopUpService.AnimationTypes.Slide:
                    storyboard = XamlReader.Load("<Storyboard xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"><DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=\"(UIElement.RenderTransform).(TranslateTransform.Y)\"><EasingDoubleKeyFrame KeyTime=\"0\" Value=\"-50\"/><EasingDoubleKeyFrame KeyTime=\"0:0:0.35\" Value=\"0\"><EasingDoubleKeyFrame.EasingFunction><ExponentialEase EasingMode=\"EaseOut\" Exponent=\"6\"/></EasingDoubleKeyFrame.EasingFunction></EasingDoubleKeyFrame></DoubleAnimationUsingKeyFrames><DoubleAnimation Storyboard.TargetProperty=\"(UIElement.Opacity)\" From=\"0\" To=\"1\" Duration=\"0:0:0.350\"><DoubleAnimation.EasingFunction><ExponentialEase EasingMode=\"EaseOut\" Exponent=\"6\"/></DoubleAnimation.EasingFunction></DoubleAnimation></Storyboard>") as Storyboard;
                    element.RenderTransform = new TranslateTransform();
                    break;

                case PopUpService.AnimationTypes.SlideInversed:
                    storyboard = XamlReader.Load("<Storyboard xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"><DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=\"(UIElement.RenderTransform).(TranslateTransform.Y)\"><SplineDoubleKeyFrame KeyTime=\"0\" Value=\"800\"/><SplineDoubleKeyFrame KeyTime=\"0:0:0.35\" Value=\"0\"><SplineDoubleKeyFrame.KeySpline><KeySpline><KeySpline.ControlPoint1><Point X=\"0.1\" Y=\"0.9\" /></KeySpline.ControlPoint1><KeySpline.ControlPoint2><Point X=\"0.2\" Y=\"1\" /></KeySpline.ControlPoint2></KeySpline></SplineDoubleKeyFrame.KeySpline></SplineDoubleKeyFrame></DoubleAnimationUsingKeyFrames><DoubleAnimation Storyboard.TargetProperty=\"(UIElement.Opacity)\" From=\"0\" To=\"1\" Duration=\"0\"/></Storyboard>") as Storyboard;
                    element.RenderTransform = new TranslateTransform();
                    break;

                case PopUpService.AnimationTypes.SlideHorizontal:
                    storyboard = XamlReader.Load("<Storyboard xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"><DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=\"(UIElement.RenderTransform).(TranslateTransform.X)\"><EasingDoubleKeyFrame KeyTime=\"0\" Value=\"-150\"/><EasingDoubleKeyFrame KeyTime=\"0:0:0.35\" Value=\"0\"><EasingDoubleKeyFrame.EasingFunction><ExponentialEase EasingMode=\"EaseOut\" Exponent=\"6\"/></EasingDoubleKeyFrame.EasingFunction></EasingDoubleKeyFrame></DoubleAnimationUsingKeyFrames><DoubleAnimation Storyboard.TargetProperty=\"(UIElement.Opacity)\" From=\"0\" To=\"1\" Duration=\"0:0:0.350\" ><DoubleAnimation.EasingFunction><ExponentialEase EasingMode=\"EaseOut\" Exponent=\"6\"/></DoubleAnimation.EasingFunction></DoubleAnimation></Storyboard>") as Storyboard;
                    element.RenderTransform = new TranslateTransform();
                    break;

                case PopUpService.AnimationTypes.Swivel:
                    storyboard = XamlReader.Load("<Storyboard xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"><DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=\"(UIElement.Projection).(PlaneProjection.RotationX)\"><EasingDoubleKeyFrame KeyTime=\"0\" Value=\"-45\"/><EasingDoubleKeyFrame KeyTime=\"0:0:0.35\" Value=\"0\"><EasingDoubleKeyFrame.EasingFunction><ExponentialEase EasingMode=\"EaseOut\" Exponent=\"6\"/></EasingDoubleKeyFrame.EasingFunction></EasingDoubleKeyFrame></DoubleAnimationUsingKeyFrames><DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=\"(UIElement.Opacity)\"><DiscreteDoubleKeyFrame KeyTime=\"0\" Value=\"1\" /></DoubleAnimationUsingKeyFrames></Storyboard>") as Storyboard;

                    PlaneProjection planeProjection = new PlaneProjection();
                    planeProjection.RotationX         = -45.0;
                    planeProjection.CenterOfRotationX = element.ActualHeight / 2.0;
                    element.Projection = planeProjection;
                    break;

                case PopUpService.AnimationTypes.Fade:
                    storyboard = XamlReader.Load("<Storyboard xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"><DoubleAnimation Duration=\"0:0:0.267\" Storyboard.TargetProperty=\"(UIElement.Opacity)\" To=\"1\"/></Storyboard>") as Storyboard;
                    break;
                }
                if (storyboard != null)
                {
                    element.Opacity = 0.0;

                    storyboard.Completed += ((s, e) =>
                    {
                        if (completionCallback != null)
                        {
                            completionCallback();
                        }
                    });
                    foreach (Timeline t in storyboard.Children)
                    {
                        Storyboard.SetTarget(t, element);
                    }

                    /*
                     * IEnumerator<Timeline> enumerator = storyboard.Children.AsEnumerable < Timeline>();
                     * try
                     * {
                     *  while (((IEnumerator)enumerator).MoveNext())
                     *      Storyboard.SetTarget(enumerator.Current, (DependencyObject)element);
                     * }
                     * finally
                     * {
                     *  if (enumerator != null)
                     *      ((IDisposable)enumerator).Dispose();
                     * }*/
                    storyboard.Begin();
                }
                else
                {
                    element.Opacity = 1.0;

                    if (completionCallback != null)
                    {
                        completionCallback();
                    }
                }
            }
        }