protected void RaiseDragDelta(RangeDragEventArgs args)
 {
     if (DragDelta != null)
     {
         DragDelta(this, args);
     }
 }
 protected void RaisePreviewEnd(RangeDragEventArgs args)
 {
     if (PreviewDragEnd != null)
     {
         PreviewDragEnd(this, args);
     }
 }
Example #3
0
        private void UpdateDraggedSource()
        {
            try
            {
                double high = HighValues[SegmentIndex], low = LowValues[SegmentIndex];
                double baseHigh = high, baseLow = low;

                DraggedValue = GetSnapToPoint(DraggedValue);
                var offset = GetSnapToPoint(DraggedValue - initialValue);
                switch (draggingMode)
                {
                case 1:
                    high = DraggedValue;
                    break;

                case 2:
                    low = DraggedValue;
                    break;

                case 3:
                    high = GetSnapToPoint(HighValues[SegmentIndex] + offset);
                    low  = GetSnapToPoint(LowValues[SegmentIndex] + offset);
                    break;
                }

                var args = new RangeDragEventArgs {
                    BaseHighValue = baseHigh, BaseLowValue = baseLow, NewHighValue = high, NewLowValue = low
                };
                RaisePreviewEnd(args);

                if (args.Cancel)
                {
                    ResetDraggingElements("", false);
                    return;
                }

                HighValues[SegmentIndex] = high;
                LowValues[SegmentIndex]  = low;

                if (UpdateSource && !IsSortData)
                {
                    UpdateUnderLayingModel(Low, SegmentIndex, LowValues[SegmentIndex]);
                    UpdateUnderLayingModel(High, SegmentIndex, HighValues[SegmentIndex]);
                }

                dragged = false;
                UpdateArea();
                var dragEvent = new RangeDragEndEventArgs {
                    BaseHighValue = baseHigh, BaseLowValue = baseLow, NewHighValue = high, NewLowValue = low
                };
                RaiseDragEnd(dragEvent);
            }
            catch
            {
                ResetDraggingElements("", false);
            }
        }
Example #4
0
        private void SegmentPreview(Point mousePos)
        {
            try
            {
                if (previewRect == null)
                {
                    return;
                }
                DraggedValue = Area.PointToValue(ActualYAxis, mousePos);
                var    currPos = IsActualTransposed ? mousePos.X : mousePos.Y;
                var    selectedRect = selectedSegment.GetRenderedVisual() as Rectangle;
                double segmentLeft = 0d, segmentTop = 0d, segmentWidth = 0d, newHigh = double.NaN, newLow = double.NaN;
                ResetDragSpliter();
                dragged = true;

                if (IsActualTransposed)
                {
                    switch (draggingMode)
                    {
                    case 1:
                    {
                        segmentWidth = Canvas.GetLeft(selectedRect);
                        var movingOffset = segmentWidth - currPos;
                        if (currPos < segmentWidth)
                        {
                            previewRect.SetValue(Canvas.LeftProperty, segmentWidth - movingOffset);
                            previewRect.Width = Math.Abs(movingOffset);
                        }
                        else
                        {
                            previewRect.SetValue(Canvas.LeftProperty, segmentWidth);
                            previewRect.Width = Math.Abs(movingOffset);
                        }

                        newHigh = DraggedValue;
                        newLow  = double.NaN;
                        UpdateSegmentDragValueToolTipHigh(new Point(mousePos.X, Canvas.GetTop(previewRect) + previewRect.Height / 2), Segments[SegmentIndex], DraggedValue, previewRect.Height / 2);
                    }

                    break;

                    case 2:
                    {
                        if (selectedRect != null)
                        {
                            segmentWidth = Canvas.GetLeft(selectedRect) + selectedRect.ActualWidth;
                        }
                        var movingOffset = segmentWidth - currPos;
                        if (currPos < segmentWidth)
                        {
                            previewRect.SetValue(Canvas.LeftProperty, segmentWidth - movingOffset);
                            previewRect.Width = Math.Abs(movingOffset);
                        }
                        else
                        {
                            previewRect.SetValue(Canvas.LeftProperty, segmentWidth);
                            previewRect.Width = Math.Abs(movingOffset);
                        }

                        newLow  = DraggedValue;
                        newHigh = double.NaN;
                        UpdateSegmentDragValueToolTipLow(new Point(mousePos.X, Canvas.GetTop(previewRect) + previewRect.Height / 2), Segments[SegmentIndex], DraggedValue);
                    }

                    break;

                    case 3:
                    {
                        segmentLeft = Canvas.GetLeft(previewRect);
                        var movingOffset = mousePos.X - initialHeight;
                        previewRect.SetValue(Canvas.LeftProperty, segmentLeft + movingOffset);
                        initialHeight = mousePos.X;
                        newHigh       = HighValues[SegmentIndex] + DraggedValue - initialValue;
                        newLow        = LowValues[SegmentIndex] + DraggedValue - initialValue;
                        UpdateSegmentDragValueToolTipHigh(new Point(Canvas.GetLeft(previewRect) + previewRect.Width, Canvas.GetTop((previewRect)) + previewRect.Height / 2), Segments[SegmentIndex], newHigh, previewRect.Width / 2);
                        UpdateSegmentDragValueToolTipLow(new Point(Canvas.GetLeft(previewRect), Canvas.GetTop(previewRect) + previewRect.Height / 2), Segments[SegmentIndex], newLow);
                    }

                    break;
                    }
                }
                else
                {
                    switch (draggingMode)
                    {
                    case 1:
                    {
                        if (selectedRect != null)
                        {
                            segmentTop = Canvas.GetTop(selectedRect) + selectedRect.ActualHeight;
                        }
                        var movingOffset = segmentTop - currPos;
                        if (currPos < segmentTop)
                        {
                            previewRect.SetValue(Canvas.TopProperty, segmentTop - movingOffset);
                            previewRect.Height = Math.Abs(movingOffset);
                        }
                        else
                        {
                            previewRect.SetValue(Canvas.TopProperty, segmentTop);
                            previewRect.Height = Math.Abs(movingOffset);
                        }

                        newHigh = DraggedValue;
                        newLow  = double.NaN;
                        UpdateSegmentDragValueToolTipHigh(new Point(Canvas.GetLeft(previewRect) + previewRect.Width / 2, mousePos.Y), Segments[SegmentIndex], DraggedValue, previewRect.Width / 2);
                    }

                    break;

                    case 2:
                    {
                        segmentTop = Canvas.GetTop(selectedRect);
                        var movingOffset = segmentTop - currPos;
                        if (currPos < segmentTop)
                        {
                            previewRect.SetValue(Canvas.TopProperty, segmentTop - movingOffset);
                            previewRect.Height = Math.Abs(movingOffset);
                        }
                        else
                        {
                            previewRect.SetValue(Canvas.TopProperty, segmentTop);
                            previewRect.Height = Math.Abs(movingOffset);
                        }

                        newLow  = DraggedValue;
                        newHigh = double.NaN;
                        UpdateSegmentDragValueToolTipLow(new Point(Canvas.GetLeft(previewRect) + previewRect.Width / 2, mousePos.Y), Segments[SegmentIndex], DraggedValue);
                    }

                    break;

                    case 3:
                    {
                        segmentTop = Canvas.GetTop(previewRect);
                        var movingOffset = initialHeight - mousePos.Y;
                        previewRect.SetValue(Canvas.TopProperty, segmentTop - movingOffset);
                        initialHeight = mousePos.Y;
                        newHigh       = HighValues[SegmentIndex] + DraggedValue - initialValue;
                        newLow        = LowValues[SegmentIndex] + DraggedValue - initialValue;
                        UpdateSegmentDragValueToolTipHigh(new Point(Canvas.GetLeft(previewRect) + previewRect.Width / 2, Canvas.GetTop((previewRect))), Segments[SegmentIndex], newHigh, previewRect.Width / 2);
                        UpdateSegmentDragValueToolTipLow(new Point(Canvas.GetLeft(previewRect) + previewRect.Width / 2, Canvas.GetTop(previewRect) + previewRect.Height), Segments[SegmentIndex], newLow);
                    }

                    break;
                    }
                }

                var dragEvent = new RangeDragEventArgs {
                    NewHighValue = newHigh, NewLowValue = newLow, BaseHighValue = HighValues[SegmentIndex], BaseLowValue = LowValues[SegmentIndex]
                };
                RaiseDragDelta(dragEvent);
                if (dragEvent.Cancel)
                {
                    ResetDraggingElements("Cancel", true);
                }
            }
            catch
            {
                ResetDraggingElements("Exception", true);
            }
        }