예제 #1
0
        private void RemoveControl()
        {
            LayerContainer.Focus();
            LayerContainer.PreventMouseEvent(null);

            if (Popup)
            {
                _control.SaftyInvoke <Popup>(p => p.IsOpen = false);
            }
            else
            {
                if (_control == null)
                {
                    return;
                }
                var panel = this.FindAncestor <Panel>();
                if (panel == null || !panel.Children.Contains(_control))
                {
                    return;
                }

                panel.Children.Remove(_control);

                _control = null;
            }

            this.FindAncestor <Panel>().ReleaseMouseCapture();
        }
예제 #2
0
        protected override void OnParentMouseUp(object sender, MouseButtonEventArgs e)
        {
            //当Popup点中ListBox选项代表结束编辑,保存
            if (Popup && !EditControlIsClosed() && e.Source == _control.SaftyGetProperty <UIElement, Popup>(o => o.Child, () => _control))
            {
                e.Handled = TryEndEdit(Key.Enter); //为了不让其选中其他Cell必须在此跳出
                return;
            }

            if (!Popup && _control != null && _editCell != InitalDrawLocation)
            {
                //int32EditBox进入编辑状态, 鼠标点其他Cell , 必须执行修改动作
                TryEndEdit(Key.Enter);
            }

            base.OnParentMouseUp(sender, e);

            if (Popup && _editCell != InitalDrawLocation && _editCell != null)
            {
                //因为双击事件会导致重新进入OnParentMouseUp, 所以需要识别InitalDrawLocation是不是点中一样的Cell, 如果点到其他Cell, 必须将Popup关闭
                RemoveControl();
                _editCell = null;
            }

            if (_editCell != InitalDrawLocation && EditControlIsClosed()) // 为了让键盘事件能够捕捉,必须LayerContainer设为焦点
            {
                LayerContainer.Focus();
            }
        }
예제 #3
0
        protected override void OnParentMouseMove(object sender, MouseEventArgs e)
        {
            if (_canMove && e.LeftButton == MouseButtonState.Pressed && PointOutBlock != null) //Henry modified: e.LeftButton == MouseButtonState.Pressed
            {
                MouseMoving(e.GetPosition(this));
                InvalidateVisual();
                e.Handled = true;

                LayerContainer.Focus();
            }
        }
예제 #4
0
        private bool AutoScroll()
        {
            var position = Mouse.GetPosition(this);

            var scrolled     = true;
            var hOffsetValue = AxisPanel.HorizontalOffSetValue;
            var hOffset      = HorizontalOffset;
            var vOffsetValue = AxisPanel.VerticalOffSetValue;
            var vOffset      = VerticalOffset;

            const double threshold = 3;

            if (position.X < threshold)
            {
                hOffset = hOffset - (hOffset / hOffsetValue);
                AxisPanel.SetHorizontalOffset(hOffset);
            }
            else if ((RenderSize.Width - threshold) < position.X)
            {
                hOffset += hOffsetValue;
                AxisPanel.SetHorizontalOffset(hOffset);
            }
            else if (position.Y < threshold)
            {
                vOffset = vOffset - (vOffset / vOffsetValue);
                AxisPanel.SetVerticalOffset(vOffset);
            }
            else if ((RenderSize.Height - threshold) < position.Y)
            {
                vOffset += vOffsetValue;
                AxisPanel.SetVerticalOffset(vOffset);
            }
            else
            {
                scrolled = false;
            }

            if (scrolled)
            {
                LayerContainer.Focus();
                Mouse.Capture(LayerContainer);
            }


            return(scrolled);
        }
예제 #5
0
        protected override void OnParentKeyDown(object sender, KeyEventArgs e)
        {
            if (Keyboard.Modifiers == ModifierKeys.Shift)
            {
                return;
            }

            if (InitalDrawLocation == null)
            {
                return;
            }

            _screenDataRowIndex = AxisPanel.GetScreenTopRowIndex();
            var prevRowIndex = AxisYConverter.ToData(InitalDrawLocation.Value.Y);

            switch (e.Key)
            {
            case Key.Left:
                MoveLeft(InitalDrawLocation.Value);
                MeasureDragingArea(_screenDataRowIndex);
                e.Handled = 0 <= ConvertToRelativePosition(_startPoint).X;
                break;

            case Key.Right:
                if (TryMoveRight(InitalDrawLocation.Value))
                {
                    MeasureDragingArea(_screenDataRowIndex);
                }
                e.Handled = ConvertToRelativePosition(_currentPoint).X <= RenderSize.Width;
                break;

            case Key.Up:
                TryMoveUp(InitalDrawLocation.Value);
                var moveUpRowIndex = AxisYConverter.ToData(_startPoint.Y);
                e.Handled = moveUpRowIndex != prevRowIndex;
                if (!e.Handled)
                {
                    _screenDataRowIndex -= _screenDataRowIndex > 0 ? 1 : 0;     // scroll up occurred
                }
                MeasureDragingArea(_screenDataRowIndex);
                break;

            case Key.Down:
                TryMoveDown(InitalDrawLocation.Value);
                var moveDownRowIndex = AxisYConverter.ToData(_startPoint.Y);

                if ((RenderSize.Height - AxisYConverter.DataToScreen(moveDownRowIndex)) < Interval)     // 屏幕最后一格未满
                {
                    e.Handled = false;
                }
                else
                {
                    e.Handled = moveDownRowIndex != prevRowIndex;
                }

                MeasureDragingArea(_screenDataRowIndex);

                if (!e.Handled)
                {
                    _screenDataRowIndex += GetItemsSourceCount() - 1 <= moveDownRowIndex ? 0 : 1;     // scroll down occurred
                }
                break;

            default:
                ClickCount = 0;
                break;
            }

            SetInitalDrawLocation();

            if (e.Handled)
            {
                InvalidateVisual(); //未发生scroll bar 卷动, 手动刷新 cell 新的位置
            }
            else
            {
                LayerContainer.Focus();
            }
            // e.Handled 如果为 false 代表由 scroll bar 滚动来引发重绘
        }