Esempio n. 1
0
        private void HandleMoveInfoByPosition(ControlActionInfo controlActionInfo, MoveInfoByPosition moveInfo)
        {
            var    control  = controlActionInfo.Control;
            var    timeSpan = moveInfo.TimeSpan;
            double width    = Double.IsNaN(control.Width) ? 0 : control.Width;
            double height   = Double.IsNaN(control.Height) ? 0 : control.Height;

            if (timeSpan.TotalMilliseconds == 0) // 如果时间间隔为0 那么直接对位置进行赋值
            {
                this.RaiseEvent(new ActionEventArgs(MovingStartEvent, this)
                {
                    Storyboard = null, ActionInfo = moveInfo
                });
                controlActionInfo.InAction = true;
                control.SetValue(Canvas.LeftProperty, moveInfo.DestX - width / 2);
                control.SetValue(Canvas.TopProperty, moveInfo.DestY - height / 2);
                controlActionInfo.InAction = false;
                this.RaiseEvent(new ActionEventArgs(MovingEndEvent, this)
                {
                    Storyboard = null, ActionInfo = moveInfo
                });
                HandleActionInfo(controlActionInfo);
            }
            else
            {
                var storyboard = new Storyboard();

                var xda = new DoubleAnimation();
                Storyboard.SetTarget(xda, control);
                Storyboard.SetTargetProperty(xda, new PropertyPath(Canvas.LeftProperty));
                xda.From     = (double)control.GetValue(Canvas.LeftProperty);
                xda.To       = (moveInfo.DestX - width / 2);
                xda.Duration = new Duration(timeSpan);

                var yda = new DoubleAnimation();
                Storyboard.SetTarget(yda, control);
                Storyboard.SetTargetProperty(yda, new PropertyPath(Canvas.TopProperty));
                yda.From     = (double)control.GetValue(Canvas.TopProperty);
                yda.To       = (moveInfo.DestY - height / 2);
                yda.Duration = new Duration(timeSpan);
                storyboard.Children.Add(xda);
                storyboard.Children.Add(yda);

                storyboard.Completed += (sender, e) =>
                {
                    controlActionInfo.InAction = false;
                    this.RaiseEvent(new ActionEventArgs(MovingEndEvent, this)
                    {
                        Storyboard = storyboard, ActionInfo = moveInfo
                    });
                    HandleActionInfo(controlActionInfo);
                };
                this.RaiseEvent(new ActionEventArgs(MovingStartEvent, this)
                {
                    Storyboard = storyboard, ActionInfo = moveInfo
                });
                storyboard.Begin(this);
                controlActionInfo.InAction = true;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 添加包含目标位置的移动信息
        /// </summary>
        /// <param name="moveInfo"></param>
        private void AddMoveInfoByPosition(MoveInfoByPosition moveInfo)
        {
            if (moveInfo == null)
            {
                throw new ArgumentNullException("moveInfo");
            }
            var control           = GetDynamicControlByName(moveInfo.ControlName);
            var controlActionInfo = m_controlActionInfoList.SingleOrDefault(o => o.Control == control);

            controlActionInfo.ActionQueue.Enqueue(moveInfo);
            HandleActionInfo(controlActionInfo);
        }