From 591f90f7bd57820d534cc819ff3e3baad667d479 Mon Sep 17 00:00:00 2001 From: subash_s Date: Tue, 29 Oct 2024 18:29:51 +0530 Subject: [PATCH] changes made --- README.md | 5 +- .../MainWindow.xaml.cs | 52 ++++++------------- 2 files changed, 16 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 83c620d..f28aaa8 100644 --- a/README.md +++ b/README.md @@ -229,7 +229,4 @@ public partial class MainWindow : Window ### Path too long exception If you are facing a path too long exception when building this example project, close Visual Studio and rename the repository to short and build the project. -For more details, refer to the KB on [How to add multiple trackballs in a WPF SfChart?](https://support.syncfusion.com/agent/kb/17741/edit). - - - +For more details, refer to the KB on [How to add multiple trackballs in a WPF SfChart?](). \ No newline at end of file diff --git a/SfChartMultipleTrackball/SfChartMultipleTrackball/MainWindow.xaml.cs b/SfChartMultipleTrackball/SfChartMultipleTrackball/MainWindow.xaml.cs index 5e440ff..9b61a67 100644 --- a/SfChartMultipleTrackball/SfChartMultipleTrackball/MainWindow.xaml.cs +++ b/SfChartMultipleTrackball/SfChartMultipleTrackball/MainWindow.xaml.cs @@ -51,36 +51,11 @@ async Task ShowTrackball() } } - public class Model - { - public string Day { get; set; } - public double CPULoad { get; set; } - } - - public class ViewModel - { - public List Data { get; set; } - - public ViewModel() - { - Data = new List - { - new Model { Day = "Monday", CPULoad = 35 }, - new Model { Day = "Tuesday", CPULoad = 42 }, - new Model { Day = "Wednesday", CPULoad = 18 }, - new Model { Day = "Thursday", CPULoad = 30 }, - new Model { Day = "Friday", CPULoad = 64 }, - new Model { Day = "Saturday", CPULoad = 22 }, - new Model { Day = "Sunday", CPULoad = 10 } - }; - } - } - public class ChartTrackBallBehaviorExt : ChartTrackBallBehavior { private bool isTrackballActive = false; - public SfChart SfChart { get; set; } + public SfChart? SfChart { get; set; } public double X { get; set; } public double Y { get; set; } @@ -121,24 +96,27 @@ protected override void OnMouseLeave(MouseEventArgs e) isTrackballActive = false; } - private ChartTrackBallBehavior FindNearestTrackball(Point touchPoint) + private ChartTrackBallBehavior? FindNearestTrackball(Point touchPoint) { - ChartTrackBallBehavior nearestTrackball = null; + ChartTrackBallBehavior? nearestTrackball = null; double minDistance = double.MaxValue; // Iterate through all trackball behaviors to find the nearest one - foreach (var trackballBehaviour in SfChart.Behaviors) + if (SfChart != null) { - if (trackballBehaviour is ChartTrackBallBehaviorExt trackball) + foreach (var trackballBehaviour in SfChart.Behaviors) { - // Calculate the distance between the trackball and the touch point - double distance = Math.Sqrt(Math.Pow(trackball.X - touchPoint.X, 2) + Math.Pow(trackball.Y - touchPoint.Y, 2)); - - // Update the nearest trackball if the current one is closer - if (distance < minDistance) + if (trackballBehaviour is ChartTrackBallBehaviorExt trackball) { - minDistance = distance; - nearestTrackball = trackball; + // Calculate the distance between the trackball and the touch point + double distance = Math.Sqrt(Math.Pow(trackball.X - touchPoint.X, 2) + Math.Pow(trackball.Y - touchPoint.Y, 2)); + + // Update the nearest trackball if the current one is closer + if (distance < minDistance) + { + minDistance = distance; + nearestTrackball = trackball; + } } } }