public void OnReplayEvent(AnimationInfo ai, Storyboard story, Path path, Button empButton) { if (ReplayEvent != null) { ReplayEvent.Invoke(ai, story, path, empButton); } }
public void OnFollowingEvent(AnimationInfo aiUC) { if (FollowingEvent != null) { FollowingEvent.Invoke(aiUC); } }
/// <summary> /// 控制同一时刻只有一个轨迹自动跟踪 /// </summary> /// <param name="ai"></param> void aniInfo_FollowingEvent(AnimationInfo ai) { foreach (AnimationInfo item in CollectionAnmInfo) { if (item != ai) { item.IsFollowing = false; } } }
/// <summary> /// 重播轨迹 /// </summary> /// <param name="ai"></param> /// <param name="story"></param> /// <param name="path"></param> /// <param name="empButton"></param> void aniInfo_ReplayEvent(AnimationInfo ai, Storyboard story, Path path, Button empButton) { CanvasMap.Children.Add(path); CanvasMap.Children.Add(empButton); Canvas.SetZIndex(path, 0); Canvas.SetTop(empButton, -empButton.Height / 2); Canvas.SetLeft(empButton, -empButton.Width / 2); story.Begin(userControlMap, true); ListButton.Add(empButton); ListPath.Add(path); }
/// <summary> /// Play Animation dependence a Button /// </summary> /// <param name="path"></param> /// <param name="empButton"></param> /// <param name="timeSp"></param> public void StartAnimation(Path path, Button empButton, int timeSp) { Storyboard stMain = new Storyboard(); AnimationInfo aniInfo = new AnimationInfo(); aniInfo.EmpName = (string)empButton.ToolTip; aniInfo.SBMain = stMain; aniInfo.UserControlBase = userControlMap; aniInfo.btnEmp = empButton; aniInfo.animaPath = path; aniInfo.CanvasBase = CanvasMap; aniInfo.ViewBoxBase = ViewBoxMap; aniInfo.CanvasRootBase = CanvasRootMap; aniInfo.FollowingEvent += new AnimationInfo.FollowingHandle(aniInfo_FollowingEvent); aniInfo.ReplayEvent += new AnimationInfo.ReplayHandle(aniInfo_ReplayEvent); stMain.Completed += (o, s) => { CanvasMap.Children.Remove(empButton);//移除动画button CanvasMap.Children.Remove(path);//移除path OnFinishedAnimationEvent(string.Format("{0}的轨迹播放完毕!", empButton.ToolTip));//通知播放完毕,没有订阅这个事件则可以不处理 aniInfo.IsFollowing = false;//取消跟踪 aniInfo.IsPaused = true;//暂停,为了重播时直接转成播放风格,而不需要转成暂停再转成播放 aniInfo.Stop(); CheckFinishedAllAnimation(); }; Canvas.SetTop(empButton, -empButton.Height / 2); Canvas.SetLeft(empButton, -empButton.Width / 2); TranslateTransform translate = new TranslateTransform(); ((TransformGroup)empButton.RenderTransform).Children.Add(translate); string RenderName = string.Format("translate{0}", RenderFlag); userControlMap.RegisterName(RenderName, translate); RenderFlag++; DoubleAnimationUsingPath animationX = new DoubleAnimationUsingPath(); animationX.PathGeometry = path.Data.GetFlattenedPathGeometry(); animationX.Source = PathAnimationSource.X; animationX.Duration = new Duration(TimeSpan.FromSeconds(timeSp)); DoubleAnimationUsingPath animationY = new DoubleAnimationUsingPath(); animationY.PathGeometry = path.Data.GetFlattenedPathGeometry(); animationY.Source = PathAnimationSource.Y; animationY.Duration = animationX.Duration; Storyboard.SetTargetProperty(animationX, new PropertyPath(TranslateTransform.XProperty)); Storyboard.SetTargetProperty(animationY, new PropertyPath(TranslateTransform.YProperty)); Storyboard.SetTargetName(animationX, RenderName); Storyboard.SetTargetName(animationY, RenderName); stMain.Children.Add(animationX); stMain.Children.Add(animationY); stMain.Begin(userControlMap, true); aniInfo.IsPaused = false; ListStoryboard.Add(stMain); ListButton.Add(empButton); ListPath.Add(path); CollectionAnmInfo.Add(aniInfo); }