-
Notifications
You must be signed in to change notification settings - Fork 678
Description
Description:
Hi, I am working on a WPF application using LiveCharts2 and I’ve encountered a limitation regarding how Zoom and Pan actions are triggered and controlled.
The Problem
Currently, ZoomAndPanMode bundles both Zoom and Pan into the same flags. This makes it difficult to implement custom input schemes. In my case, I want to:
-
Disable default mouse behavior: Prevent accidental panning/zooming (especially when using PointerPressedCommand for other logic).
-
Keyboard-triggered actions: Use specific keys (e.g., F1 for Pan, F2/F3 for Zoom) to trigger these movements.
Issues encountered
-
If I set ZoomMode="None" in XAML to prevent accidental mouse interaction, calling cartesianChartEngine.Zoom(ZoomAndPanMode.Both | ZoomAndPanMode.NoFit, ...) manually in the ViewModel ignores the NoFit flag. The chart tries to fit to bounds.
-
Even if I temporarily toggle ZoomMode to Both inside the command, it does not work.
-
There is no easy way to enable "Pan only" or "Zoom only" without them interfering with other mouse-down/drag logic.
Suggestions
It would be highly beneficial if the library could:
-
Decouple Zoom and Pan: Separate the enums or the logic so we can enable Panning independently from Zooming (e.g., ZoomMode.OnlyPanX).
-
Input Mapping Strategy: Allow users to define which PointerEvent or Key triggers a Pan or Zoom.
-
Honoring Flags in cartesianChartEngine.Zoom: Ensure that when calling cartesianChartEngine.Zoom manually, the passed ZoomAndPanMode flags (like NoFit) strictly override any global ZoomMode settings.
Current Workaround attempt (which fails to respect NoFit):
// This does not respect NoFit if the XAML was set to ZoomMode="None".
// If the last line is commented out, NoFit is respected, but Panning remains enabled.
[RelayCommand]
public virtual void ZoomInOut(ZoomDirection zoomDirection)
{
if (CurrentChartPoint is ChartPoint chartPoint && (zoomDirection == ZoomDirection.ZoomIn || zoomDirection == ZoomDirection.ZoomOut))
{
var cartesianChart = (CartesianChart)chartPoint.Context.Chart;
var core = (CartesianChartEngine)cartesianChart.CoreChart;
int scaleYAt = ((ILineSeries)chartPoint.Context.Series).ScalesYAt;
LvcPointD pivot = cartesianChart.ScaleDataToPixels(
new LvcPointD(chartPoint.Coordinate.SecondaryValue, chartPoint.Coordinate.PrimaryValue), 0, scaleYAt);
// Temporarily enabling ZoomMode to allow the operation
cartesianChart.ZoomMode = ZoomAndPanMode.Both | ZoomAndPanMode.NoFit;
core.Zoom(ZoomAndPanMode.Both | ZoomAndPanMode.NoFit, new LvcPoint(pivot.X, pivot.Y), zoomDirection);
// This reset causes NoFit to be ignored during the subsequent update/animation cycle.
cartesianChart.ZoomMode = ZoomAndPanMode.None;
}
}I believe providing more granular control over the input triggers would make LiveCharts2 much more flexible for professional CAD-like or data-heavy interfaces.
Desktop:
OS: Windows 11 Pro
Platform: WPF (.NET 8)
Version 2.0.0-rc6.1