public void updateTimebarStoryBoardIn() { //时间轴动画 var tg = new TransformGroup(); var translation = new TranslateTransform(); var translationName = "myTranslation" + translation.GetHashCode(); timebar.RegisterName(translationName, translation); tg.Children.Add(translation); timebar.ShowTimeBar.RenderTransform = tg; DoubleAnimation myDoubleAnimation = new DoubleAnimation(); myDoubleAnimation.From = 0;// keyFrame.Image.Margin.Left; double rate = (-(0 == zoomLayout ? InkCanvasOffsetX : InkCanvasOffsetX - preInkCanvasOffsetX) - InkCanvas.Margin.Left) / ((0 == zoomLayout ? 25 : 37) * 120 + 30); rate = (rate >= 1?0.9:rate); ShowTimerbarOffsetX = rate * timebar.Width - timebar.ShowTimeBar.Margin.Left; preInkCanvasOffsetX = (0 == zoomLayout?InkCanvasOffsetX:0); ShowTimerbarOffsetX = (ShowTimerbarOffsetX < 0 ? -timebar.ShowTimeBar.Margin.Left : ShowTimerbarOffsetX); myDoubleAnimation.To = ShowTimerbarOffsetX; myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(MoveTime)); Storyboard.SetTargetName(myDoubleAnimation, translationName); Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath(TranslateTransform.XProperty)); timebar.RegisterName("showTimebar", timebar.ShowTimeBar); DoubleAnimation myDoubleAnimationWidth = new DoubleAnimation(); myDoubleAnimationWidth.From = timebar.ShowTimeBar.Width; double toWidth = parentInkcanvas.ActualWidth / ((0 == zoomLayout ? 25 : 37) * 120 + 30) * timebar.Width; toWidth = (ShowTimerbarOffsetX + timebar.ShowTimeBar.Margin.Left + toWidth > timebar.Width? timebar.Width - timebar.ShowTimeBar.Margin.Left - ShowTimerbarOffsetX:toWidth); toWidth = (toWidth < 0 ? 10 : toWidth); toWidth = (ShowTimerbarOffsetX + timebar.ShowTimeBar.Margin.Left + toWidth > timebar.TotalTimeBar.Width ? timebar.TotalTimeBar.Width - ShowTimerbarOffsetX - timebar.ShowTimeBar.Margin.Left : toWidth); myDoubleAnimationWidth.To = toWidth; myDoubleAnimationWidth.Duration = new Duration(TimeSpan.FromSeconds(MoveTime)); Storyboard.SetTargetName(myDoubleAnimationWidth, timebar.ShowTimeBar.Name); Storyboard.SetTargetProperty(myDoubleAnimationWidth, new PropertyPath(Rectangle.WidthProperty)); var s = new Storyboard(); var storyboardName = "s" + s.GetHashCode(); s.Children.Add(myDoubleAnimation); s.Children.Add(myDoubleAnimationWidth); s.Completed += new EventHandler(sIn_Completed); s.Begin(timebar); }