/// <summary> /// 鼠标移动,判断从哪个方向进入 /// </summary> private void MyImageButtom_MouseMove(object sender, MouseEventArgs e) { if (!IsCanMove) { return; } EntryDirection direction = EntryDirection.None; Point tempEndPoint = e.GetPosition(this); if (IsInRect(tempEndPoint.X, tempEndPoint.Y, LRect)) { direction = EntryDirection.Left; } else if (IsInRect(tempEndPoint.X, tempEndPoint.Y, TRect)) { direction = EntryDirection.Top; } else if (IsInRect(tempEndPoint.X, tempEndPoint.Y, RRect)) { direction = EntryDirection.Right; } else if (IsInRect(tempEndPoint.X, tempEndPoint.Y, BRect)) { direction = EntryDirection.Bottom; } AppearAnimate(direction); IsCanMove = false; }
/// <summary> /// 鼠标离开,判断从哪个方向离开 /// </summary> private void MyImageButtom_MouseLeave(object sender, MouseEventArgs e) { EntryDirection direction = EntryDirection.None; Point tempEndPoint = e.GetPosition(this); if (IsInRect(tempEndPoint.X, tempEndPoint.Y, DLRect)) { direction = EntryDirection.Left; } else if (IsInRect(tempEndPoint.X, tempEndPoint.Y, DTRect)) { direction = EntryDirection.Top; } else if (IsInRect(tempEndPoint.X, tempEndPoint.Y, DRRect)) { direction = EntryDirection.Right; } else if (IsInRect(tempEndPoint.X, tempEndPoint.Y, DBRect)) { direction = EntryDirection.Bottom; } DisappearAnimate(direction); }
/// <summary> /// 鼠标移出消失动图 /// </summary> private void DisappearAnimate(EntryDirection direction) { storyboard.Children.Clear(); DoubleAnimation RotateTransformAnimation; switch (direction) { case EntryDirection.Left: this.imgHover.RenderTransformOrigin = new Point(0, 1); RotateTransformAnimation = new DoubleAnimation(0, -90, new Duration(TimeSpan.FromMilliseconds(500))); break; case EntryDirection.Top: this.imgHover.RenderTransformOrigin = new Point(0, 0); RotateTransformAnimation = new DoubleAnimation(0, -90, new Duration(TimeSpan.FromMilliseconds(500))); break; case EntryDirection.Right: this.imgHover.RenderTransformOrigin = new Point(1, 1); RotateTransformAnimation = new DoubleAnimation(0, 90, new Duration(TimeSpan.FromMilliseconds(500))); break; case EntryDirection.Bottom: this.imgHover.RenderTransformOrigin = new Point(0, 1); RotateTransformAnimation = new DoubleAnimation(0, 90, new Duration(TimeSpan.FromMilliseconds(500))); break; default: return; } Storyboard.SetTarget(RotateTransformAnimation, this.imgHover); Storyboard.SetTargetProperty(RotateTransformAnimation, new PropertyPath("(0).(1)", propertyChain)); storyboard.Children.Add(RotateTransformAnimation); storyboard.Begin(); Canvas.SetZIndex(this.imgHover, 0); }