private static ObjectAnimationUsingKeyFrames CreateAnimation(IList<ImageSource> imageFrames)
        {
            // Initialize the animation for this object.
            var result = new ObjectAnimationUsingKeyFrames
            {
                Duration = s_animationDuration,
            };

            // Creates the frames for the animation.
            var frameDuration = FullDuration / s_lightFrames.Value.Count;
            int framePoint = 0;
            var keyFrames = new ObjectKeyFrameCollection();
            foreach (var frame in imageFrames)
            {
                var keyFrame = new DiscreteObjectKeyFrame
                {
                    KeyTime = new TimeSpan(0, 0, 0, 0, framePoint),
                    Value = frame,
                };
                keyFrames.Add(keyFrame);

                framePoint += frameDuration;
            }
            result.KeyFrames = keyFrames;

            return result;
        }
示例#2
0
        public void StartFlapping(TimeSpan interval)
        {
            List<string> imageNames = new List<string>() {
            "Bee animation 1.png", "Bee animation 2.png", "Bee animation 3.png", "Bee animation 4.png"
        };

            Storyboard storyboard = new Storyboard();
            ObjectAnimationUsingKeyFrames animation = new ObjectAnimationUsingKeyFrames();
            Storyboard.SetTarget(animation, image);
            Storyboard.SetTargetProperty(animation, new PropertyPath("Source"));

            TimeSpan currentInteval = TimeSpan.FromMilliseconds(0);
            foreach (string imageName in imageNames)
            {
                ObjectKeyFrame keyFrame = new DiscreteObjectKeyFrame();
                keyFrame.Value = CreateImageFromAssets(imageName);
                keyFrame.KeyTime = currentInteval;
                animation.KeyFrames.Add(keyFrame);
                currentInteval = currentInteval.Add(interval);
            }

            storyboard.RepeatBehavior = RepeatBehavior.Forever;
            storyboard.AutoReverse = true;
            storyboard.Children.Add(animation);
            storyboard.Begin();
        }
        public void AnimateImage(IEnumerable<string> imageNames, TimeSpan interval)
        {
            var storyboard = new Storyboard
            {
                RepeatBehavior = RepeatBehavior.Forever
            };

            var animation = new ObjectAnimationUsingKeyFrames();
            Storyboard.SetTarget(animation, this);
            Storyboard.SetTargetProperty(animation, new PropertyPath("Background"));

            var currentInterval = TimeSpan.FromMilliseconds(0);
            foreach (var imageName in imageNames)
            {
                var keyFrame = new DiscreteObjectKeyFrame
                {
                    Value = CreateImageFromAssets(imageName),
                    KeyTime = currentInterval
                };
                animation.KeyFrames.Add(keyFrame);
                currentInterval = currentInterval.Add(interval);
            }

            storyboard.Children.Add(animation);

            storyboard.Begin();
        }
        public void CreateFlashStoryBoard(TimeSpan interval)
        {
            flashStoryboard = new Storyboard();
            ObjectAnimationUsingKeyFrames animation = new ObjectAnimationUsingKeyFrames();
            Storyboard.SetTarget(animation, image);
            Storyboard.SetTargetProperty(animation, new PropertyPath(Control.VisibilityProperty));

            TimeSpan currentInterval = TimeSpan.FromMilliseconds(0);
            ObjectKeyFrame keyFrameVisible = new DiscreteObjectKeyFrame();
            keyFrameVisible.Value = Visibility.Visible;
            keyFrameVisible.KeyTime = currentInterval;

            animation.KeyFrames.Add(keyFrameVisible);
            currentInterval = currentInterval.Add(interval);

            ObjectKeyFrame keyFrameHidden = new DiscreteObjectKeyFrame();
            keyFrameHidden.Value = Visibility.Hidden;
            keyFrameHidden.KeyTime = currentInterval;

            animation.KeyFrames.Add(keyFrameHidden);
            currentInterval = currentInterval.Add(interval);

            flashStoryboard.RepeatBehavior = RepeatBehavior.Forever;
            flashStoryboard.AutoReverse = true;
            flashStoryboard.Children.Add(animation);
        }
 private static ObjectAnimationUsingKeyFrames CreateVisibilityAnimation(Duration duration, DependencyObject element, bool show)
 {
     var animation = new ObjectAnimationUsingKeyFrames();
     animation.BeginTime = duration.HasTimeSpan ? duration.TimeSpan : new TimeSpan();
     animation.KeyFrames.Add(new DiscreteObjectKeyFrame { KeyTime = new TimeSpan(0), Value = (show ? Visibility.Visible : Visibility.Collapsed) });
     Storyboard.SetTargetProperty(animation, new PropertyPath("Visibility"));
     Storyboard.SetTarget(animation, element);
     return animation;
 }
示例#6
0
        /// <summary>
        /// 隐藏窗口
        /// </summary>
        /// <param name="window">要隐藏的窗口</param>
        public void HideWindow(Window window)
        {
            ObjectAnimationUsingKeyFrames visAni = new ObjectAnimationUsingKeyFrames();
            visAni.KeyFrames.Add(new DiscreteObjectKeyFrame(Visibility.Hidden, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.3))));
            window.BeginAnimation(Window.VisibilityProperty, visAni);

            DoubleAnimationUsingKeyFrames alphaAni = new DoubleAnimationUsingKeyFrames();
            CubicEase ef = new CubicEase();
            alphaAni.KeyFrames.Add(new EasingDoubleKeyFrame(1, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)), ef));
            alphaAni.KeyFrames.Add(new EasingDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.3)), ef));
            window.BeginAnimation(Window.OpacityProperty, alphaAni);
        }
 internal static AnimationContext Discrete(
     this AnimationContext target, DependencyProperty propertyPath, params object[] args)
 {
     List<object> list = args.ToList();
     if ((args.Length%2) != 0)
     {
         throw new InvalidOperationException("Params should come in a time-value pair");
     }
     target.StartIndex = target.EndIndex;
     target.EndIndex += target.Targets.Count;
     int num = 0;
     foreach (FrameworkElement element in target.Targets)
     {
         if (target.IsUpdate)
         {
             var frames = target.Instance.Children[target.StartIndex + num] as ObjectAnimationUsingKeyFrames;
             if (frames != null)
             {
                 for (int j = 0; j < list.Count; j += 2)
                 {
                     var frame = frames.KeyFrames[j/2] as DiscreteObjectKeyFrame;
                     if (frame != null)
                     {
                         frame.KeyTime =
                             KeyTime.FromTimeSpan(
                                 TimeSpan.FromSeconds(Convert.ToDouble(list[j], CultureInfo.InvariantCulture)));
                         frame.Value = list[j + 1];
                     }
                 }
             }
             num++;
             continue;
         }
         var frames2 = new ObjectAnimationUsingKeyFrames();
         Storyboard.SetTarget(frames2, element);
         Storyboard.SetTargetProperty(frames2, new PropertyPath(propertyPath));
         for (int i = 0; i < list.Count; i += 2)
         {
             frames2.KeyFrames.Add(
                 new DiscreteObjectKeyFrame
                     {
                         KeyTime =
                             KeyTime.FromTimeSpan(
                                 TimeSpan.FromSeconds(Convert.ToDouble(list[i], CultureInfo.InvariantCulture))),
                         Value = list[i + 1]
                     });
         }
         target.Instance.Children.Add(frames2);
     }
     return target;
 }
        internal ImageAnimationController(Image image, ObjectAnimationUsingKeyFrames animation, bool autoStart)
        {
            _image = image;
            _animation = animation;
            _animation.Completed += AnimationCompleted;
            _clock = _animation.CreateClock();
            _clockController = _clock.Controller;
            _sourceDescriptor.AddValueChanged(image, ImageSourceChanged);

            // ReSharper disable once PossibleNullReferenceException
            _clockController.Pause();

            _image.ApplyAnimationClock(Image.SourceProperty, _clock);

            if (autoStart)
                _clockController.Resume();
        }
示例#9
0
 /// <summary>
 /// 创建Point类型的关键帧动画
 /// </summary>
 /// <param name="Model">动画数据</param>
 /// <returns></returns>
 public static ObjectAnimationUsingKeyFrames BuildObjectKeyFramesAnimation(ObjectKeyFramesModel Model)
 {
     ObjectAnimationUsingKeyFrames _objectAnimation = new ObjectAnimationUsingKeyFrames();
     _objectAnimation.Duration = (Model.Duration == 0 ? Duration.Automatic : new Duration(TimeSpan.FromSeconds(Model.Duration)));
     _objectAnimation.AutoReverse = Model.AutoReverse;
     _objectAnimation.BeginTime = TimeSpan.FromSeconds(Model.BeginTime);
     _objectAnimation.FillBehavior = Model.FillBehavior;
     _objectAnimation.RepeatBehavior = Model.RepeatBehavior;
     _objectAnimation.SpeedRatio = Model.SpeedRatio;
     foreach (var item in Model.KeyFrames)
     {
         _objectAnimation.KeyFrames.Add(CreateColorKeyFrmas(item));
     }
     Storyboard.SetTarget(_objectAnimation, Model.Target);
     Storyboard.SetTargetProperty(_objectAnimation, new PropertyPath(Model.PropertyPath));
     return _objectAnimation;
 }
示例#10
0
        private void Button_Clicked(object sender, MouseButtonEventArgs e)
        {
            var animation = new DoubleAnimation(_border.ActualHeight, 0, new Duration(new TimeSpan(0, 0, 0, 1)));
            animation.EasingFunction = new PowerEase() { Power = 8};
            _border.BeginAnimation(HeightProperty, animation);

            var opacityAnimation = new DoubleAnimation(_border.Opacity, 0, new Duration(new TimeSpan(0, 0, 0, 1)));
            opacityAnimation.EasingFunction = new PowerEase() { Power = 8 };
            _border.BeginAnimation(OpacityProperty, opacityAnimation);

            var objectAnimation = new ObjectAnimationUsingKeyFrames();
            objectAnimation.KeyFrames.Add(new DiscreteObjectKeyFrame(null, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.5))));
            this.BeginAnimation(SelectedItemProperty, objectAnimation);

            var visibilityAnimation = new ObjectAnimationUsingKeyFrames();
            visibilityAnimation.KeyFrames.Add(new DiscreteObjectKeyFrame(Visibility.Hidden, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.5))));
            _button.BeginAnimation(VisibilityProperty, visibilityAnimation);
        }
        ObjectAnimationUsingKeyFrames GetAnimation(bool start)
        {
            var animation = new ObjectAnimationUsingKeyFrames();
            if (!start)
            {

                animation.Duration = TimeSpan.FromSeconds(1.5);
                animation.RepeatBehavior = RepeatBehavior.Forever;
                animation.KeyFrames.Add(new DiscreteObjectKeyFrame(System.Windows.Visibility.Visible, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.0))));
                animation.KeyFrames.Add(new DiscreteObjectKeyFrame(System.Windows.Visibility.Hidden, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.5))));
                animation.KeyFrames.Add(new DiscreteObjectKeyFrame(System.Windows.Visibility.Visible, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1.0))));
                animation.KeyFrames.Add(new DiscreteObjectKeyFrame(System.Windows.Visibility.Hidden, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1.5))));
            }
            else
            {
                animation.Duration = Duration.Forever;
                animation.KeyFrames.Add(new DiscreteObjectKeyFrame(System.Windows.Visibility.Visible));
            }
            return animation;
        }
        public void StartAnimation(IEnumerable<string> imageNames, TimeSpan interval)
        {
            Storyboard storyboard = new Storyboard();
            ObjectAnimationUsingKeyFrames animation = new ObjectAnimationUsingKeyFrames();
            Storyboard.SetTarget(animation, image);
            Storyboard.SetTargetProperty(animation, new PropertyPath(Image.SourceProperty));

            TimeSpan currentInterval = TimeSpan.FromMilliseconds(0);
            foreach (string imageName in imageNames)
            {
                ObjectKeyFrame keyFrame = new DiscreteObjectKeyFrame();
                keyFrame.Value = CreateImageFromAssets(imageName);
                keyFrame.KeyTime = currentInterval;
                animation.KeyFrames.Add(keyFrame);
                currentInterval = currentInterval.Add(interval);
            }

            storyboard.RepeatBehavior = RepeatBehavior.Forever;
            storyboard.AutoReverse = true;
            storyboard.Children.Add(animation);
            storyboard.Begin();
        }
示例#13
0
        protected override Storyboard CreateStoryboard(FrameworkElement target)
        {
            Storyboard storyboard = new Storyboard();
            ObjectAnimationUsingKeyFrames animation = new ObjectAnimationUsingKeyFrames();
            Debugger.Log(1,"",animation.KeyFrames.ToString());
            DiscreteObjectKeyFrame keyFrame =  new DiscreteObjectKeyFrame();
            KeyTime keyTime = KeyTime.FromTimeSpan(new TimeSpan(0));
            keyFrame.KeyTime = keyTime;
            keyFrame.Value=Visibility.Visible;

            DiscreteObjectKeyFrame keyFrame2 = new DiscreteObjectKeyFrame();
            KeyTime keyTime2 = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(250));
            keyFrame2.KeyTime = keyTime2;
            keyFrame2.Value=Visibility.Collapsed;

            animation.KeyFrames.Add(keyFrame);
            animation.KeyFrames.Add(keyFrame2);
            animation.SpeedRatio = Speed;
            storyboard.Children.Add(animation);
            Storyboard.SetTarget(animation, target);
            Storyboard.SetTargetProperty(animation, new PropertyPath(Image.VisibilityProperty));
            return storyboard;
        }
        public static void ShowHidePrincipal(Window window, string target, EventHandler OnComplete, Visibility visibility)
        {
            int seconds = 1;
            Storyboard storyboard = new Storyboard();
            TimeSpan time = new TimeSpan(0, 0, seconds);

            DoubleAnimation animationFade = new DoubleAnimation(
                visibility == Visibility.Hidden ? 0 : 1,
                new Duration(time));
            Storyboard.SetTargetName(animationFade, target);
            Storyboard.SetTargetProperty(animationFade, new PropertyPath(Frame.OpacityProperty));

            ObjectAnimationUsingKeyFrames animationHide = new ObjectAnimationUsingKeyFrames();
            ObjectKeyFrame hideFrame = new DiscreteObjectKeyFrame(visibility, KeyTime.FromTimeSpan(time));
            animationHide.KeyFrames.Add(hideFrame);
            Storyboard.SetTargetName(animationHide, target);
            Storyboard.SetTargetProperty(animationHide, new PropertyPath(Frame.VisibilityProperty));

            storyboard.Children.Add(animationFade);
            storyboard.Children.Add(animationHide);
            storyboard.Completed += OnComplete;
            
            storyboard.Begin(window);
        }
示例#15
0
        private void Button_Clicked(object sender, MouseButtonEventArgs e)
        {
            var animation = new DoubleAnimation(_border.ActualHeight, 0, new Duration(new TimeSpan(0, 0, 0, 1)));
            animation.EasingFunction = new PowerEase() { Power = 8};
            _border.BeginAnimation(HeightProperty, animation);

            var opacityAnimation = new DoubleAnimation(_border.Opacity, 0, new Duration(new TimeSpan(0, 0, 0, 1)));
            opacityAnimation.EasingFunction = new PowerEase() { Power = 8 };
            _border.BeginAnimation(OpacityProperty, opacityAnimation);

            var objectAnimation = new ObjectAnimationUsingKeyFrames();
            objectAnimation.KeyFrames.Add(new DiscreteObjectKeyFrame(null, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.5))));
            this.BeginAnimation(SelectedItemProperty, objectAnimation);

            var visibilityAnimation = new ObjectAnimationUsingKeyFrames();
            visibilityAnimation.KeyFrames.Add(new DiscreteObjectKeyFrame(Visibility.Hidden, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.5))));
            _button.BeginAnimation(VisibilityProperty, visibilityAnimation);

            //var selectedAnimation = new BooleanAnimationUsingKeyFrames();
            //selectedAnimation.KeyFrames.Add(new DiscreteBooleanKeyFrame(false, KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 1))));
            //_border.BeginAnimation(SelectedItemProperty, selectedAnimation);

            #region Old Code

            //this.SelectedItem = null;

            //foreach (TabItem child in _tabPanel.Children)
            //{
            //    child.IsSelected = false;
            //}

            //_border.Visibility = Visibility.Collapsed;
            //_button.Visibility = Visibility.Collapsed;

            #endregion
        }
 public static UIElement FadeFromTo(this UIElement uiElement,
     double fromOpacity, double toOpacity,
     int durationInMilliseconds, bool loopAnimation, bool showOnStart, bool collapseOnFinish)
 {
     var timeSpan = TimeSpan.FromMilliseconds(durationInMilliseconds);
     var doubleAnimation =
         new DoubleAnimation(fromOpacity, toOpacity,
             new Duration(timeSpan));
     if (loopAnimation)
         doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
     uiElement.BeginAnimation(UIElement.OpacityProperty, doubleAnimation);
     if (showOnStart)
     {
         uiElement.ApplyAnimationClock(UIElement.VisibilityProperty, null);
         uiElement.Visibility = Visibility.Visible;
     }
     if (collapseOnFinish)
     {
         var keyAnimation = new ObjectAnimationUsingKeyFrames { Duration = new Duration(timeSpan) };
         keyAnimation.KeyFrames.Add(new DiscreteObjectKeyFrame(Visibility.Collapsed, KeyTime.FromTimeSpan(timeSpan)));
         uiElement.BeginAnimation(UIElement.VisibilityProperty, keyAnimation);
     }
     return uiElement;
 }
示例#17
0
 public void InitializeComponent() {
     if (_contentLoaded) {
         return;
     }
     _contentLoaded = true;
     System.Windows.Application.LoadComponent(this, new System.Uri("/ChuOngThongMinh;component/HoneyJar.xaml", System.UriKind.Relative));
     this.userControl = ((System.Windows.Controls.UserControl)(this.FindName("userControl")));
     this.StbShake = ((System.Windows.Media.Animation.Storyboard)(this.FindName("StbShake")));
     this.StbAddPoint = ((System.Windows.Media.Animation.Storyboard)(this.FindName("StbAddPoint")));
     this.obaStbAddPoint100_01 = ((System.Windows.Media.Animation.ObjectAnimationUsingKeyFrames)(this.FindName("obaStbAddPoint100_01")));
     this.damStbAddPoint100_02 = ((System.Windows.Media.Animation.DoubleAnimationUsingKeyFrames)(this.FindName("damStbAddPoint100_02")));
     this.StbEliminatePoint = ((System.Windows.Media.Animation.Storyboard)(this.FindName("StbEliminatePoint")));
     this.obaEliminatePoint600_01 = ((System.Windows.Media.Animation.ObjectAnimationUsingKeyFrames)(this.FindName("obaEliminatePoint600_01")));
     this.obaEliminatePoint600_02 = ((System.Windows.Media.Animation.DoubleAnimationUsingKeyFrames)(this.FindName("obaEliminatePoint600_02")));
     this.obaEliminatePoint600_03 = ((System.Windows.Media.Animation.DoubleAnimationUsingKeyFrames)(this.FindName("obaEliminatePoint600_03")));
     this.imgJar = ((System.Windows.Controls.Image)(this.FindName("imgJar")));
     this.imgHoneyFull = ((System.Windows.Controls.Image)(this.FindName("imgHoneyFull")));
     this.imgHoneyNotFull = ((System.Windows.Controls.Image)(this.FindName("imgHoneyNotFull")));
     this.tblMath = ((System.Windows.Controls.TextBlock)(this.FindName("tblMath")));
     this.imgAdd100Points = ((System.Windows.Controls.Image)(this.FindName("imgAdd100Points")));
     this.imgAdd250Points = ((System.Windows.Controls.Image)(this.FindName("imgAdd250Points")));
     this.imgAdd500Points = ((System.Windows.Controls.Image)(this.FindName("imgAdd500Points")));
     this.imgEliminate60Points = ((System.Windows.Controls.Image)(this.FindName("imgEliminate60Points")));
     this.imgEliminate100Points = ((System.Windows.Controls.Image)(this.FindName("imgEliminate100Points")));
     this.imgEliminate200Points = ((System.Windows.Controls.Image)(this.FindName("imgEliminate200Points")));
     this.imgGreenHexagonal = ((System.Windows.Controls.Image)(this.FindName("imgGreenHexagonal")));
     this.imgOrangeHexagonal = ((System.Windows.Controls.Image)(this.FindName("imgOrangeHexagonal")));
     this.imgVioletHexagonal = ((System.Windows.Controls.Image)(this.FindName("imgVioletHexagonal")));
 }
示例#18
0
        //private void invalidateButton()
        //{
        //    foreach (Button key in keyList)
        //    {
        //        key.IsEnabled = false;
        //    }
        //}

        //private void validateButton()
        //{
        //    foreach (Button key in keyList)
        //    {
        //        key.IsEnabled = true;
        //    }
        //}


        private void keyClick(object sender, RoutedEventArgs e)
        {
            string ans = "";
            string nextQuestion = "";
            Button keyButton = null;
            if (sender is Button)
            {
                keyButton = (Button)sender;
                ans = keyButton.Name;
            }

            DiscreteObjectKeyFrame setImageFrame = new DiscreteObjectKeyFrame();
            DiscreteObjectKeyFrame clearImageFrame = new DiscreteObjectKeyFrame();
            DiscreteObjectKeyFrame setQuestionFrame = new DiscreteObjectKeyFrame();
            setImageFrame.KeyTime = new TimeSpan(0, 0, 0, 0);
            clearImageFrame.KeyTime = new TimeSpan(0, 0, 0, 0, 700);
            clearImageFrame.Value = clearImage;
            setQuestionFrame.KeyTime = new TimeSpan(0, 0, 0, 0, 700);

            nextQuestion = game.IsCorrect(ans);
            if (nextQuestion == "false")
            {
                setImageFrame.Value = falseImage;
                mainWindow.setStatus("False.");
                setQuestionFrame.Value = qTextBox.Text;
                missCount++;
            }
            else if (nextQuestion == "end")
            {
                Page p = new ResultPage(mainWindow.StopTimer(),missCount);
                mainWindow.setStatus("Finish!");
                NavigationService.Navigate(p);
            }
            else
            {
                setImageFrame.Value = correctImage;
                //rightOrWrongImage.Source = correctImage;
                mainWindow.setStatus("Correct.");
                this.qTextBox.Text = nextQuestion;
                //setQuestionFrame.Value = nextQuestion;
            }
            ObjectAnimationUsingKeyFrames rightOrWrongAnimation = new ObjectAnimationUsingKeyFrames();
            rightOrWrongAnimation.BeginTime = new TimeSpan(0,0,0,0);
            rightOrWrongAnimation.KeyFrames.Add(setImageFrame);
            rightOrWrongAnimation.KeyFrames.Add(clearImageFrame);

            ObjectAnimationUsingKeyFrames questionAnimation = new ObjectAnimationUsingKeyFrames();
            questionAnimation.BeginTime = new TimeSpan(0, 0, 0, 0);
            questionAnimation.KeyFrames.Add(setQuestionFrame);

            Storyboard gameStoryboard = new Storyboard();
            gameStoryboard.Children.Add(rightOrWrongAnimation);
            Storyboard.SetTargetName(rightOrWrongAnimation, rightOrWrongImage.Name);
            Storyboard.SetTargetProperty(rightOrWrongAnimation, new PropertyPath(Image.SourceProperty));

            //gameStoryboard.Children.Add(questionAnimation);
            //Storyboard.SetTargetName(questionAnimation, qTextBox.Name);
            //Storyboard.SetTargetProperty(questionAnimation,new PropertyPath(TextBlock.TextProperty));

            gameStoryboard.Begin(this);
        }
示例#19
0
文件: Popup.cs 项目: 925coder/ravendb
 private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 {
     // in lieu of DependencyObject.SetCurrentValue, this is the easiest way to enact a change on the value of the Popup's IsOpen
     // property without overwriting any binding that may exist on it
     var storyboard = new Storyboard() { Duration = TimeSpan.Zero };
     var objectAnimation = new ObjectAnimationUsingKeyFrames() { Duration = TimeSpan.Zero };
     objectAnimation.KeyFrames.Add(new DiscreteObjectKeyFrame() { KeyTime = KeyTime.FromTimeSpan(TimeSpan.Zero), Value = false });
     Storyboard.SetTarget(objectAnimation, this.popup);
     Storyboard.SetTargetProperty(objectAnimation, new PropertyPath("IsOpen"));
     storyboard.Children.Add(objectAnimation);
     storyboard.Begin();
 }
示例#20
0
        private void _CreateCueLines()
        {
            if (_cueLines != null)
            {
                foreach (var line in _cueLines.Values)
                {
                    GlobalCanvas.Children.Remove(line.Key);
                    GlobalCanvas.Children.Remove(line.Value);
                }
            }

            _cueLines = new Dictionary<KeyValuePair<Player, Player>, KeyValuePair<Line, Line>>();
            _lineUpAnimations = new Dictionary<KeyValuePair<Player, Player>, Timeline>();
            foreach (var source in playersMap.Keys)
            {
                foreach (var target in playersMap.Keys)
                {
                    if (source == target) continue;
                    var key = new KeyValuePair<Player, Player>(source, target);

                    Line line = new Line();
                    line.StrokeDashCap = PenLineCap.Triangle;
                    line.StrokeThickness = 1;
                    line.Stroke = Resources["indicatorLineBrush"] as Brush;
                    line.Visibility = Visibility.Collapsed;
                    line.SetValue(Canvas.ZIndexProperty, _cueLineZIndex);

                    Line line2 = new Line();
                    line2.StrokeDashCap = PenLineCap.Triangle;
                    line2.StrokeThickness = 3;
                    line2.Stroke = Resources["indicatorLineGlowBrush"] as Brush;
                    line2.Visibility = Visibility.Collapsed;
                    line2.SetValue(Canvas.ZIndexProperty, _cueLineZIndex - 1);

                    _cueLines.Add(key, new KeyValuePair<Line, Line>(line, line2));

                    var anim1 = new DoubleAnimation();
                    anim1.Duration = _lineUpDuration;
                    Storyboard.SetTarget(anim1, line);
                    Storyboard.SetTargetProperty(anim1, new PropertyPath(Line.StrokeDashOffsetProperty));
                    var anim2 = new ObjectAnimationUsingKeyFrames();
                    anim2.Duration = _lineUpDuration;
                    anim2.KeyFrames.Add(new DiscreteObjectKeyFrame(Visibility.Visible, KeyTime.FromPercent(0)));
                    anim2.KeyFrames.Add(new DiscreteObjectKeyFrame(Visibility.Collapsed, KeyTime.FromPercent(1)));
                    Storyboard.SetTarget(anim2, line);
                    Storyboard.SetTargetProperty(anim2, new PropertyPath(Line.VisibilityProperty));

                    var anim3 = new DoubleAnimation();
                    anim3.Duration = _lineUpDuration;
                    Storyboard.SetTarget(anim3, line2);
                    Storyboard.SetTargetProperty(anim3, new PropertyPath(Line.StrokeDashOffsetProperty));
                    var anim4 = new ObjectAnimationUsingKeyFrames();
                    anim4.Duration = _lineUpDuration;
                    anim4.KeyFrames.Add(new DiscreteObjectKeyFrame(Visibility.Visible, KeyTime.FromPercent(0)));
                    anim4.KeyFrames.Add(new DiscreteObjectKeyFrame(Visibility.Collapsed, KeyTime.FromPercent(1)));
                    Storyboard.SetTarget(anim4, line2);
                    Storyboard.SetTargetProperty(anim4, new PropertyPath(Line.VisibilityProperty));

                    Storyboard animation = new Storyboard();
                    animation.FillBehavior = FillBehavior.Stop;
                    animation.Children.Add(anim1);
                    animation.Children.Add(anim2);
                    animation.Children.Add(anim3);
                    animation.Children.Add(anim4);
                    animation.Duration = _lineUpDuration;

                    _lineUpAnimations.Add(key, animation);

                    GlobalCanvas.Children.Add(line2);
                    GlobalCanvas.Children.Add(line);
                }
            }
        }
示例#21
0
		public void ZeroDurationStoryboard ()
		{
			int completeCount = 0;
			Storyboard sb = new Storyboard ();
			
			sb.Completed += delegate { completeCount ++; };

			ObjectAnimationUsingKeyFrames anim = new ObjectAnimationUsingKeyFrames { Duration = TimeSpan.FromMilliseconds (0) };
			anim.KeyFrames.Add (new DiscreteObjectKeyFrame { KeyTime = TimeSpan.FromSeconds (0), Value = "1" });
			sb.Children.Add (anim);

			Rectangle target = new Rectangle ();
			Storyboard.SetTarget (anim, target);
			Storyboard.SetTargetProperty (anim, new PropertyPath (Rectangle.WidthProperty));

			sb.Begin ();

			// Wait 200ms
			long start = Environment.TickCount;
			EnqueueConditional (() => Environment.TickCount - start > 200, "#1");
			Enqueue (() => Assert.AreEqual (1, completeCount, "#2"));
			EnqueueTestComplete ();
		}
示例#22
0
		public void TargetGridLength ()
		{
			bool completed = false;
			Storyboard sb = new Storyboard ();
			sb.Completed += delegate {
				completed = true;
			};

			ObjectAnimationUsingKeyFrames anim = new ObjectAnimationUsingKeyFrames { Duration=TimeSpan.FromMilliseconds (1) };
			anim.KeyFrames.Add (new DiscreteObjectKeyFrame { KeyTime = TimeSpan.FromSeconds (0), Value = "*" });
			sb.Children.Add (anim);

			ColumnDefinition target = new ColumnDefinition { Width = new GridLength (5) };
			Storyboard.SetTarget (anim, target);
			Storyboard.SetTargetProperty (anim, new PropertyPath (ColumnDefinition.WidthProperty));

			sb.Begin ();

			// First animate a '*' value
			EnqueueConditional (() => completed, "#2");
			Enqueue (() => {
				Assert.IsTrue (target.Width.IsStar, "#3");
				Assert.AreEqual (1, target.Width.Value, "#4");
			});

			// Then check 'Auto'
			Enqueue (() => {
				anim.KeyFrames [0].Value = "Auto";
				completed = false;
				sb.Begin ();
			});
			EnqueueConditional (() => completed, "#5");
			Enqueue (() => {
				Assert.IsTrue (target.Width.IsAuto, "#6");
				Assert.AreEqual (GridUnitType.Auto, target.Width.GridUnitType, "#7");
				Assert.AreEqual (1, target.Width.Value, "#8");
			});

			// Then check a number
			Enqueue (() => {
				anim.KeyFrames [0].Value = "5";
				completed = false;
				sb.Begin ();
			});
			EnqueueConditional (() => completed, "#9");
			Enqueue (() => {
				Assert.AreEqual (GridUnitType.Pixel, target.Width.GridUnitType, "#10");
				Assert.AreEqual (5, target.Width.Value, "#11");
			});
			
			EnqueueTestComplete ();
		}
 public void InitializeComponent()
 {
     if (_contentLoaded)
     {
         return;
     }
     _contentLoaded = true;
     System.Windows.Application.LoadComponent(this, new System.Uri("/Zires%20Explorer;component/Player/VideoPlayer.xaml", System.UriKind.Relative));
     this.Open_Controls  = ((System.Windows.Media.Animation.Storyboard)(this.FindName("Open_Controls")));
     this.Close_Controls = ((System.Windows.Media.Animation.Storyboard)(this.FindName("Close_Controls")));
     this.objectAnimationUsingKeyFrames   = ((System.Windows.Media.Animation.ObjectAnimationUsingKeyFrames)(this.FindName("objectAnimationUsingKeyFrames")));
     this.doubleAnimationUsingKeyFrames_1 = ((System.Windows.Media.Animation.DoubleAnimationUsingKeyFrames)(this.FindName("doubleAnimationUsingKeyFrames_1")));
     this.doubleAnimationUsingKeyFrames_2 = ((System.Windows.Media.Animation.DoubleAnimationUsingKeyFrames)(this.FindName("doubleAnimationUsingKeyFrames_2")));
     this.Open_Zoompage                 = ((System.Windows.Media.Animation.Storyboard)(this.FindName("Open_Zoompage")));
     this.Close_Zoompage                = ((System.Windows.Media.Animation.Storyboard)(this.FindName("Close_Zoompage")));
     this.Open_detailsPage              = ((System.Windows.Media.Animation.Storyboard)(this.FindName("Open_detailsPage")));
     this.Close_detailsPage             = ((System.Windows.Media.Animation.Storyboard)(this.FindName("Close_detailsPage")));
     this.LayoutRoot                    = ((System.Windows.Controls.Grid)(this.FindName("LayoutRoot")));
     this.background                    = ((System.Windows.Controls.Grid)(this.FindName("background")));
     this.ContentPanel                  = ((System.Windows.Controls.ScrollViewer)(this.FindName("ContentPanel")));
     this.player                        = ((System.Windows.Controls.MediaElement)(this.FindName("player")));
     this.controls                      = ((System.Windows.Controls.Grid)(this.FindName("controls")));
     this.AudioControls                 = ((System.Windows.Controls.Grid)(this.FindName("AudioControls")));
     this.controlsButtomPlaneProjection = ((System.Windows.Media.PlaneProjection)(this.FindName("controlsButtomPlaneProjection")));
     this.durationHours                 = ((System.Windows.Controls.TextBlock)(this.FindName("durationHours")));
     this.durationMinutes               = ((System.Windows.Controls.TextBlock)(this.FindName("durationMinutes")));
     this.durationSeconds               = ((System.Windows.Controls.TextBlock)(this.FindName("durationSeconds")));
     this.Dimensions                    = ((System.Windows.Controls.TextBlock)(this.FindName("Dimensions")));
     this.lenght                        = ((System.Windows.Controls.TextBlock)(this.FindName("lenght")));
     this.slider                        = ((System.Windows.Controls.Slider)(this.FindName("slider")));
     this.play     = ((System.Windows.Controls.Button)(this.FindName("play")));
     this.pause    = ((System.Windows.Controls.Button)(this.FindName("pause")));
     this.pau      = ((System.Windows.Media.PlaneProjection)(this.FindName("pau")));
     this.stop     = ((System.Windows.Controls.Button)(this.FindName("stop")));
     this.sto      = ((System.Windows.Media.PlaneProjection)(this.FindName("sto")));
     this.next     = ((System.Windows.Controls.Button)(this.FindName("next")));
     this.nex      = ((System.Windows.Media.PlaneProjection)(this.FindName("nex")));
     this.previous = ((System.Windows.Controls.Button)(this.FindName("previous")));
     this.pre      = ((System.Windows.Media.PlaneProjection)(this.FindName("pre")));
     this.inFo     = ((System.Windows.Controls.Button)(this.FindName("inFo")));
     this.pre1     = ((System.Windows.Media.PlaneProjection)(this.FindName("pre1")));
     this.zoom     = ((System.Windows.Controls.Button)(this.FindName("zoom")));
     this.sto1     = ((System.Windows.Media.PlaneProjection)(this.FindName("sto1")));
     this.Stretch  = ((System.Windows.Controls.Primitives.ToggleButton)(this.FindName("Stretch")));
     this.Stre     = ((System.Windows.Media.PlaneProjection)(this.FindName("Stre")));
     this.controlsTopPlaneProjection = ((System.Windows.Media.PlaneProjection)(this.FindName("controlsTopPlaneProjection")));
     this.name                   = ((System.Windows.Controls.TextBlock)(this.FindName("name")));
     this.time                   = ((System.Windows.Controls.TextBlock)(this.FindName("time")));
     this.zoomPage               = ((System.Windows.Controls.Border)(this.FindName("zoomPage")));
     this.ZoomPlaneProjection    = ((System.Windows.Media.PlaneProjection)(this.FindName("ZoomPlaneProjection")));
     this.ZoomPageBack           = ((System.Windows.Controls.Button)(this.FindName("ZoomPageBack")));
     this.PlaneProjection1       = ((System.Windows.Media.PlaneProjection)(this.FindName("PlaneProjection1")));
     this.PlaneProjection2       = ((System.Windows.Media.PlaneProjection)(this.FindName("PlaneProjection2")));
     this.PlaneProjection3       = ((System.Windows.Media.PlaneProjection)(this.FindName("PlaneProjection3")));
     this.PlaneProjection4       = ((System.Windows.Media.PlaneProjection)(this.FindName("PlaneProjection4")));
     this.PlaneProjection5       = ((System.Windows.Media.PlaneProjection)(this.FindName("PlaneProjection5")));
     this.detailsPage            = ((System.Windows.Controls.Grid)(this.FindName("detailsPage")));
     this.PlaneProjectionDetails = ((System.Windows.Media.PlaneProjection)(this.FindName("PlaneProjectionDetails")));
     this.detailsPageBack        = ((System.Windows.Controls.Button)(this.FindName("detailsPageBack")));
     this.detailsName            = ((System.Windows.Controls.TextBlock)(this.FindName("detailsName")));
     this.detailsFrameWidth      = ((System.Windows.Controls.TextBlock)(this.FindName("detailsFrameWidth")));
     this.detailsFrameHeight     = ((System.Windows.Controls.TextBlock)(this.FindName("detailsFrameHeight")));
     this.detailsLength          = ((System.Windows.Controls.TextBlock)(this.FindName("detailsLength")));
     this.detailsFolderPath      = ((System.Windows.Controls.TextBlock)(this.FindName("detailsFolderPath")));
     this.detailsSize            = ((System.Windows.Controls.TextBlock)(this.FindName("detailsSize")));
     this.detailsDateCreated     = ((System.Windows.Controls.TextBlock)(this.FindName("detailsDateCreated")));
     this.detailsLastAccessTime  = ((System.Windows.Controls.TextBlock)(this.FindName("detailsLastAccessTime")));
 }
        /// <summary> 
        /// Helper used by the four Freezable clone methods to copy the resolved key times and
        /// key frames. The Get*AsFrozenCore methods are implemented the same as the Clone*Core 
        /// methods; Get*AsFrozen at the top level will recursively Freeze so it's not done here. 
        /// </summary>
        /// <param name="sourceAnimation"></param> 
        /// <param name="isCurrentValueClone"></param>
        private void CopyCommon(ObjectAnimationUsingKeyFrames sourceAnimation, bool isCurrentValueClone)
        {
            _areKeyTimesValid = sourceAnimation._areKeyTimesValid; 

            if (   _areKeyTimesValid 
                && sourceAnimation._sortedResolvedKeyFrames != null) 
            {
                // _sortedResolvedKeyFrames is an array of ResolvedKeyFrameEntry so the notion of CurrentValueClone doesn't apply 
                _sortedResolvedKeyFrames = (ResolvedKeyFrameEntry[])sourceAnimation._sortedResolvedKeyFrames.Clone();
            }

            if (sourceAnimation._keyFrames != null) 
            {
                if (isCurrentValueClone) 
                { 
                    _keyFrames = (ObjectKeyFrameCollection)sourceAnimation._keyFrames.CloneCurrentValue();
                } 
                else
                {
                    _keyFrames = (ObjectKeyFrameCollection)sourceAnimation._keyFrames.Clone();
                } 

                OnFreezablePropertyChanged(null, _keyFrames); 
            } 
        }
        public Task StopAsync()
        {
            TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();

            if (_Running != true)
            {
                tcs.SetResult(null);
                return tcs.Task;
            }

            Storyboard SB = new Storyboard();

            _Running = false;

            double cangle = RotateTransform.Angle;

            int Nb = (int)Math.Round((360 - cangle) / 45) + 1;

            DoubleAnimationUsingKeyFrames dauk = new DoubleAnimationUsingKeyFrames();
            for (int i = 0; i < 17; i++)
            {
                DiscreteDoubleKeyFrame first = new DiscreteDoubleKeyFrame(cangle + 45 * i, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(i * Frequency)));
                dauk.KeyFrames.Add(first);
            }
            Storyboard.SetTarget(dauk, VB);
            Storyboard.SetTargetProperty(dauk, new PropertyPath("(RenderTransform).(RotateTransform.Angle)"));
            SB.Children.Add(dauk);

            for (int i = 0; i < 8; i++)
            {
                ObjectAnimationUsingKeyFrames oauk = new ObjectAnimationUsingKeyFrames();

                oauk.RepeatBehavior = new RepeatBehavior(1);

                DiscreteObjectKeyFrame first = new DiscreteObjectKeyFrame(Visibility.Visible, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(Frequency * Nb)));
                oauk.KeyFrames.Add(first);
                DiscreteObjectKeyFrame first_1 = new DiscreteObjectKeyFrame(Visibility.Collapsed, KeyTime.FromTimeSpan(TimeSpan.FromSeconds((i + Nb) * Frequency)));
                oauk.KeyFrames.Add(first_1);
                DiscreteObjectKeyFrame second = new DiscreteObjectKeyFrame(Visibility.Collapsed, KeyTime.FromTimeSpan(TimeSpan.FromSeconds((i + Nb) * Frequency)));
                oauk.KeyFrames.Add(second);

                Storyboard.SetTarget(oauk, this.FindName(string.Format("E{0}", i)) as DependencyObject);
                Storyboard.SetTargetProperty(oauk, new PropertyPath("Visibility"));

                SB.Children.Add(oauk);
            }

            _SB.Stop();
           
            EventHandler handler = null;
            handler = delegate
            {
                SB.Completed -= handler;
                tcs.SetResult(null);
            };
            SB.Completed += handler;
            SB.Begin();

            return tcs.Task;
        }
        private void Root_Loaded(object sender, RoutedEventArgs e)
        {
            _SB = new Storyboard();

            DoubleAnimationUsingKeyFrames dauk = new DoubleAnimationUsingKeyFrames();
            dauk.RepeatBehavior = RepeatBehavior.Forever;
            for (int i = 0; i < 9; i++)
            {
                DiscreteDoubleKeyFrame first = new DiscreteDoubleKeyFrame(45 * i, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(i * Frequency)));
                dauk.KeyFrames.Add(first);
            }
            Storyboard.SetTarget(dauk, VB);
            Storyboard.SetTargetProperty(dauk, new PropertyPath("(RenderTransform).(RotateTransform.Angle)"));
            _SB.Children.Add(dauk);



            for (int i = 1; i < 8; i++)
            {
                ObjectAnimationUsingKeyFrames oauk = new ObjectAnimationUsingKeyFrames();

                oauk.RepeatBehavior = new RepeatBehavior(1);

                DiscreteObjectKeyFrame first = new DiscreteObjectKeyFrame(Visibility.Collapsed, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)));
                oauk.KeyFrames.Add(first);
                DiscreteObjectKeyFrame first_1 = new DiscreteObjectKeyFrame(Visibility.Collapsed, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(i * Frequency)));
                oauk.KeyFrames.Add(first_1);
                DiscreteObjectKeyFrame second = new DiscreteObjectKeyFrame(Visibility.Visible, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(i * Frequency)));
                oauk.KeyFrames.Add(second);

                Storyboard.SetTarget(oauk, this.FindName(string.Format("E{0}", i)) as DependencyObject);
                Storyboard.SetTargetProperty(oauk, new PropertyPath("Visibility"));

                _SB.Children.Add(oauk);
            }

            Start();
        }
示例#27
0
 public static void AddAnimation(ImageSource source, RepeatBehavior repeatBehavior, ObjectAnimationUsingKeyFrames animation)
 {
     var key = new CacheKey(source, repeatBehavior);
     _animationCache[key] = animation;
 }
示例#28
0
        /// <summary>
        /// Reveals data points using a storyboard.
        /// </summary>
        /// <param name="dataPoints">The data points to change the state of.
        /// </param>
        /// <param name="dataPointCount">The number of data points in the sequence.</param>
        /// <param name="newState">The state to change to.</param>
        private void StaggeredStateChange(IEnumerable<DataPoint> dataPoints, int dataPointCount, DataPointState newState)
        {
            if (PlotArea == null || dataPointCount == 0)
            {
                return;
            }

            string guid = Guid.NewGuid().ToString();
            Storyboard stateChangeStoryBoard = new Storyboard();
            stateChangeStoryBoard.Completed +=
                (sender, args) =>
                {
                    PlotArea.Resources.Remove(guid);
                };

            dataPoints.ForEachWithIndex((dataPoint, count) =>
            {
                // Create an Animation
                ObjectAnimationUsingKeyFrames objectAnimationUsingKeyFrames = new ObjectAnimationUsingKeyFrames();
                Storyboard.SetTarget(objectAnimationUsingKeyFrames, dataPoint);
                Storyboard.SetTargetProperty(objectAnimationUsingKeyFrames, new PropertyPath("State"));

                // Create a key frame
                DiscreteObjectKeyFrame discreteObjectKeyFrame = new DiscreteObjectKeyFrame();
                discreteObjectKeyFrame.Value = newState;

                // Create the specified animation type
                switch (AnimationSequence)
                {
                    case AnimationSequence.Simultaneous:
                        discreteObjectKeyFrame.KeyTime = TimeSpan.Zero;
                        break;
                    case AnimationSequence.FirstToLast:
                        discreteObjectKeyFrame.KeyTime = TimeSpan.FromMilliseconds(1000 * ((double)count / dataPointCount));
                        break;
                    case AnimationSequence.LastToFirst:
                        discreteObjectKeyFrame.KeyTime = TimeSpan.FromMilliseconds(1000 * ((double)(dataPointCount - count - 1) / dataPointCount));
                        break;
                }

                // Add the Animation to the Storyboard
                objectAnimationUsingKeyFrames.KeyFrames.Add(discreteObjectKeyFrame);
                stateChangeStoryBoard.Children.Add(objectAnimationUsingKeyFrames);
            });

            _storyBoardQueue.Enqueue(stateChangeStoryBoard);
        }
 private static Storyboard CreateStoryboard(this DependencyObject target, DependencyProperty animatingDependencyProperty, string propertyPath, string propertyKey, ref object toValue, TimeSpan durationTimeSpan, IEasingFunction easingFunction)
 {
     object obj = target.GetValue(animatingDependencyProperty);
     Storyboard storyboard = new Storyboard();
     Storyboard.SetTarget((DependencyObject)storyboard, target);
     Storyboard.SetTargetProperty((DependencyObject)storyboard, new PropertyPath(propertyPath, new object[0]));
     if (obj != null && toValue != null)
     {
         double doubleValue1;
         double doubleValue2;
         if (ValueHelper.TryConvert(obj, out doubleValue1) && ValueHelper.TryConvert(toValue, out doubleValue2))
         {
             DoubleAnimation doubleAnimation = new DoubleAnimation();
             doubleAnimation.Duration = (Duration)durationTimeSpan;
             doubleAnimation.To = new double?(ValueHelper.ToDouble(toValue));
             toValue = (object)doubleAnimation.To;
             storyboard.Children.Add((Timeline)doubleAnimation);
         }
         else
         {
             DateTime dateTimeValue1;
             DateTime dateTimeValue2;
             if (ValueHelper.TryConvert(obj, out dateTimeValue1) && ValueHelper.TryConvert(toValue, out dateTimeValue2))
             {
                 ObjectAnimationUsingKeyFrames animationUsingKeyFrames = new ObjectAnimationUsingKeyFrames();
                 animationUsingKeyFrames.Duration = (Duration)durationTimeSpan;
                 long count = (long)(durationTimeSpan.TotalSeconds * 20.0);
                 if (count < 2L)
                     count = 2L;
                 IEnumerable<TimeSpan> intervalsInclusive = ValueHelper.GetTimeSpanIntervalsInclusive(durationTimeSpan, count);
                 foreach (DiscreteObjectKeyFrame discreteObjectKeyFrame in Enumerable.Zip<DateTime, TimeSpan, DiscreteObjectKeyFrame>(ValueHelper.GetDateTimesBetweenInclusive(dateTimeValue1, dateTimeValue2, count), intervalsInclusive, (Func<DateTime, TimeSpan, DiscreteObjectKeyFrame>)((dateTime, timeSpan) =>
                {
                    return new DiscreteObjectKeyFrame()
                    {
                        Value = (object)dateTime,
                        KeyTime = (KeyTime)timeSpan
                    };
                })))
                 {
                     animationUsingKeyFrames.KeyFrames.Add((ObjectKeyFrame)discreteObjectKeyFrame);
                     toValue = discreteObjectKeyFrame.Value;
                 }
                 storyboard.Children.Add((Timeline)animationUsingKeyFrames);
             }
         }
     }
     if (storyboard.Children.Count == 0)
     {
         ObjectAnimationUsingKeyFrames animationUsingKeyFrames = new ObjectAnimationUsingKeyFrames();
         DiscreteObjectKeyFrame discreteObjectKeyFrame1 = new DiscreteObjectKeyFrame();
         discreteObjectKeyFrame1.Value = toValue;
         discreteObjectKeyFrame1.KeyTime = (KeyTime)new TimeSpan(0, 0, 0);
         DiscreteObjectKeyFrame discreteObjectKeyFrame2 = discreteObjectKeyFrame1;
         animationUsingKeyFrames.KeyFrames.Add((ObjectKeyFrame)discreteObjectKeyFrame2);
         storyboard.Children.Add((Timeline)animationUsingKeyFrames);
     }
     return storyboard;
 }
        /// <summary>
        /// 初始化报警帧动画
        /// </summary>
        private void InitAlertAnimation()
        {
            sbAlert = new Storyboard();
            sbAlert.RepeatBehavior = RepeatBehavior.Forever;
            this.RegisterName("spAlert", StackPanelAlert);

            ObjectAnimationUsingKeyFrames oaKeyFrames = new ObjectAnimationUsingKeyFrames();

            DiscreteObjectKeyFrame doKey0 = new DiscreteObjectKeyFrame();
            doKey0.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0));
            doKey0.Value = Visibility.Visible;

            DiscreteObjectKeyFrame doKey1 = new DiscreteObjectKeyFrame();
            doKey1.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.5));
            doKey1.Value = Visibility.Hidden;

            DiscreteObjectKeyFrame doKey2 = new DiscreteObjectKeyFrame();
            doKey2.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1));
            doKey2.Value = Visibility.Visible;

            oaKeyFrames.KeyFrames.Add(doKey0);
            oaKeyFrames.KeyFrames.Add(doKey1);
            oaKeyFrames.KeyFrames.Add(doKey2);

            Storyboard.SetTargetName(oaKeyFrames, "spAlert");
            Storyboard.SetTargetProperty(oaKeyFrames, new PropertyPath(VisibilityProperty));

            sbAlert.Children.Add(oaKeyFrames);
        }
示例#31
0
 public static void RemoveAnimation(ImageSource source, RepeatBehavior repeatBehavior, ObjectAnimationUsingKeyFrames animation)
 {
     var key = new CacheKey(source, repeatBehavior);
     _animationCache.Remove(key);
 }