Ejemplo n.º 1
0
        /// <summary>
        /// function for moving the control
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        private void ProcessMove(double x, double y)
        {
            var width  = _partOverlay./*RenderSize.*/ Width;
            var height = _partOverlay./*RenderSize.*/ Height;
            var offset = TreeExtensions.GetOffsetFrom(this, _partWindow);
            //var offset = VisualTreeHelper.GetOffset(this.partWindow);
            //todo correct me
            var widthOffset  = offset.M11; // offset.X;
            var heightOffset = offset.M12; //offset.Y;

            var realX = _moveTransform.X + x + widthOffset;
            var realY = _moveTransform.Y + y + heightOffset;

            const int extraGap  = 5;
            var       widthGap  = Math.Max(_icon?./*Actual*/ Width + 5 ?? 30, 30);
            var       heightGap = Math.Max(this.TitleBarHeight, 30);
            var       changeX   = _moveTransform.X;
            var       changeY   = _moveTransform.Y;

            if (realX < (0 + extraGap))
            {
                changeX = -widthOffset + extraGap;
            }
            else if (realX > (width - widthGap - extraGap))
            {
                changeX = width - widthOffset - widthGap - extraGap;
            }
            else
            {
                changeX += x;
            }

            if (realY < (0 + extraGap))
            {
                changeY = -heightOffset + extraGap;
            }
            else if (realY > (height - heightGap - extraGap))
            {
                changeY = height - heightOffset - heightGap - extraGap;
            }
            else
            {
                changeY += y;
            }

            if (!Equals(changeX, _moveTransform.X) || !Equals(changeY, _moveTransform.Y))
            {
                this.SetValue(OffsetXProperty, changeX);
                this.SetValue(OffsetYProperty, changeY);

                this.InvalidateArrange();
            }
        }