1: private void BeginIndicatorAnimation()
2: {
3: Storyboard indicatorStoryboard = new Storyboard();
4:
5: _animatedImage = new Image();
6: _animatedImage.Source = _indicatoritems.IndicatorSmallImage;
7: _animatedImage.Height = 200;
8: _animatedImage.Width = 200;
9: _animatedImage.VerticalAlignment = VerticalAlignment.Top;
10: _animatedImage.HorizontalAlignment = HorizontalAlignment.Left;
11: _animatedImage.Margin = new Thickness(0, 0, 0, 0);
12:
13: Grid grid = (Grid)this.FindName("grid");
14: ConvertTargetToImage(grid);
15:
16: grid.Children.Add(_animatedImage);
17:
18: System.Windows.Markup.INameScope currentNameScope = NameScope.GetNameScope(this);
19: NameScope.SetNameScope(this, new NameScope());
20:
21: _animatedImage.Name = "adornLayer";
22: this.RegisterName(_animatedImage.Name, _animatedImage);
23:
24: TranslateTransform animatedTranslateTransform = new TranslateTransform();
25: this.RegisterName("AnimatedTranslateTransform", animatedTranslateTransform);
26:
27: ScaleTransform animatedScaleTransform = new ScaleTransform();
28: this.RegisterName("AnimatedScaleTransform", animatedScaleTransform);
29:
30: TransformGroup transformGroup = new TransformGroup();
31: transformGroup.Children.Add(animatedScaleTransform);
32: transformGroup.Children.Add(animatedTranslateTransform);
33:
34: _animatedImage.RenderTransformOrigin = new Point(0.5, 0.5);
35: _animatedImage.RenderTransform = transformGroup;
36:
37: //Create Animation Path
38: PathGeometry pathGeometry = new PathGeometry();
39: PathFigure pathFigure = new PathFigure();
40:
41: double x = (CurrentPosition.X - (_animatedImage.Width / 2));
42: double y = (CurrentPosition.Y - (_animatedImage.Height / 2));
43:
44: pathFigure.StartPoint = new Point(x, y);
45: pathFigure.Segments.Add(new LineSegment(new Point(980 - 120 * (_indicatoritems.MealIndicatorCount - ++_indicatoritems.CurrentIndex), 90), true));
46:
47: pathGeometry.Figures.Add(pathFigure);
48: pathGeometry.Freeze();
49:
50: //Create Animation
51: //Opactiy
52: DoubleAnimation opacityAnimation = new DoubleAnimation();
53: opacityAnimation.From = 1.0;
54: opacityAnimation.To = 0.0;
55: opacityAnimation.AccelerationRatio = 1.0;
56: opacityAnimation.Duration = new Duration(TimeSpan.FromSeconds(1.0));
57: Storyboard.SetTargetName(opacityAnimation, _animatedImage.Name);
58: Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath(Image.OpacityProperty));
59:
60: //translate X to Path
61: DoubleAnimationUsingPath translateXAnimation = new DoubleAnimationUsingPath();
62: translateXAnimation.PathGeometry = pathGeometry;
63: translateXAnimation.Duration = TimeSpan.FromSeconds(1.0);
64: translateXAnimation.Source = PathAnimationSource.X;
65: translateXAnimation.AccelerationRatio = 1.0;
66:
67: Storyboard.SetTargetName(translateXAnimation, "AnimatedTranslateTransform");
68: Storyboard.SetTargetProperty(translateXAnimation,
69: new PropertyPath(TranslateTransform.XProperty));
70:
71: //Translate Y to Path
72: DoubleAnimationUsingPath translateYAnimation = new DoubleAnimationUsingPath();
73: translateYAnimation.PathGeometry = pathGeometry;
74: translateYAnimation.Duration = TimeSpan.FromSeconds(1.0);
75: translateYAnimation.Source = PathAnimationSource.Y;
76:
77: Storyboard.SetTargetName(translateYAnimation, "AnimatedTranslateTransform");
78: Storyboard.SetTargetProperty(translateYAnimation,
79: new PropertyPath(TranslateTransform.YProperty));
80:
81: DoubleAnimation scaleXAnimation = new DoubleAnimation(0.4, new Duration(TimeSpan.FromSeconds(1.1)));
82: Storyboard.SetTargetName(scaleXAnimation, "AnimatedScaleTransform");
83: Storyboard.SetTargetProperty(scaleXAnimation, new PropertyPath(ScaleTransform.ScaleXProperty));
84:
85: DoubleAnimation scaleYAnimation = new DoubleAnimation(0.4, new Duration(TimeSpan.FromSeconds(1.1)));
86: Storyboard.SetTargetName(scaleYAnimation, "AnimatedScaleTransform");
87: Storyboard.SetTargetProperty(scaleYAnimation, new PropertyPath(ScaleTransform.ScaleYProperty));
88:
89: indicatorStoryboard.Children.Clear();
90: indicatorStoryboard.Children.Add(scaleXAnimation);
91: indicatorStoryboard.Children.Add(scaleYAnimation);
92: indicatorStoryboard.Children.Add(translateXAnimation);
93: indicatorStoryboard.Children.Add(translateYAnimation);
94: indicatorStoryboard.Children.Add(opacityAnimation);
95: indicatorStoryboard.FillBehavior = FillBehavior.Stop;
96:
97: TimeSpan s = indicatorStoryboard.Children.Max(z => z.Duration.TimeSpan);
98: EventAggregator.GetEvent<HitTestDelayEvent>().Publish(s);
99:
100: _sbPopupAnimation = indicatorStoryboard.Clone();
101: _sbPopupAnimation.Name = "Indicator";
102: _sbPopupAnimation.Completed += PopupStoryBoardEndCompleted;
103: _sbPopupAnimation.Begin(this);
104:
105: NameScope.SetNameScope(this, currentNameScope);
106: }