/// <summary> /// Called on ManipulationDelta event detected on Y axis rectangle. Used to change axis scale easily /// </summary> private void ChartScroll_ManipulationYDelta(object sender, ManipulationDeltaRoutedEventArgs e) { // Make sure that the scale has changed by a sufficient amount to change the chart scale if (Math.Abs(e.Delta.Scale - 1.0) >= 0.01) { // Make sure that the scale is within the bounds if (ChartYScale <= MaxChartYScale && ChartYScale >= MinChartYScale) { ChartYScale *= 1.0 + 0.5 * (e.Delta.Scale - 1.0); // Make sure the scale doesn't jump outside the bounds if (ChartYScale < MinChartYScale) { ChartYScale = MinChartYScale; } if (ChartYScale > MaxChartYScale) { ChartYScale = MaxChartYScale; } // Change the height if the chart to match the new scale ExpenseChart.Height = PivotItem2.ActualHeight * ChartYScale; } // If the scale is outside the bounds, scale back else if (ChartYScale < MinChartYScale) { ChartYScale = MinChartYScale; ExpenseChart.Height = PivotItem2.ActualHeight * ChartYScale; } else if (ChartYScale > MaxChartYScale) { ChartYScale = MaxChartYScale; ExpenseChart.Height = PivotItem2.ActualHeight * ChartYScale; } } // Adjust the position to the allow for dragging in the axis double NewPosition = ChartScroll.VerticalOffset * ChartYScale + e.Delta.Translation.Y; ChartScroll.ChangeView(ChartScroll.HorizontalOffset, NewPosition, ChartScroll.ZoomFactor, true); }
private void AdjustGridSize() { double actualWidth = _maxObjectX - _minObjectX; double actualHeight = _maxObjectY - _minObjectY; double rightExtraWidth = 0.00; if (_maxObjectX > ChartCanvas.Width) { rightExtraWidth = _maxObjectX - ChartCanvas.Width + ElementMargin; } double leftExtraWidth = 0.00; if (_minObjectX < 0.00) { leftExtraWidth = Math.Abs(_minObjectX) + ElementMargin; } double lowerExtraHeight = 0.00; if (_maxObjectY > ChartCanvas.Height) { lowerExtraHeight = _maxObjectY - ChartCanvas.Height + ElementMargin; } double upperExtraHeight = 0.00; if (_minObjectY < 0.00) { upperExtraHeight = Math.Abs(_minObjectY) + ElementMargin; } double horisontalPadding = Math.Max(leftExtraWidth, rightExtraWidth); double verticalPadding = Math.Max(lowerExtraHeight, upperExtraHeight); ChartGrid.Width = horisontalPadding * 2 + ChartCanvas.Width; ChartGrid.Height = verticalPadding * 2 + ChartCanvas.Height; ChartScroll.ScrollToHorizontalOffset(horisontalPadding); ChartScroll.ScrollToVerticalOffset(verticalPadding); }