Skip to content

Commit 591f90f

Browse files
committed
changes made
1 parent 5c912ce commit 591f90f

File tree

2 files changed

+16
-41
lines changed

2 files changed

+16
-41
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,4 @@ public partial class MainWindow : Window
229229
### Path too long exception
230230
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.
231231

232-
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).
233-
234-
235-
232+
For more details, refer to the KB on [How to add multiple trackballs in a WPF SfChart?]().

SfChartMultipleTrackball/SfChartMultipleTrackball/MainWindow.xaml.cs

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -51,36 +51,11 @@ async Task ShowTrackball()
5151
}
5252
}
5353

54-
public class Model
55-
{
56-
public string Day { get; set; }
57-
public double CPULoad { get; set; }
58-
}
59-
60-
public class ViewModel
61-
{
62-
public List<Model> Data { get; set; }
63-
64-
public ViewModel()
65-
{
66-
Data = new List<Model>
67-
{
68-
new Model { Day = "Monday", CPULoad = 35 },
69-
new Model { Day = "Tuesday", CPULoad = 42 },
70-
new Model { Day = "Wednesday", CPULoad = 18 },
71-
new Model { Day = "Thursday", CPULoad = 30 },
72-
new Model { Day = "Friday", CPULoad = 64 },
73-
new Model { Day = "Saturday", CPULoad = 22 },
74-
new Model { Day = "Sunday", CPULoad = 10 }
75-
};
76-
}
77-
}
78-
7954
public class ChartTrackBallBehaviorExt : ChartTrackBallBehavior
8055
{
8156
private bool isTrackballActive = false;
8257

83-
public SfChart SfChart { get; set; }
58+
public SfChart? SfChart { get; set; }
8459

8560
public double X { get; set; }
8661
public double Y { get; set; }
@@ -121,24 +96,27 @@ protected override void OnMouseLeave(MouseEventArgs e)
12196
isTrackballActive = false;
12297
}
12398

124-
private ChartTrackBallBehavior FindNearestTrackball(Point touchPoint)
99+
private ChartTrackBallBehavior? FindNearestTrackball(Point touchPoint)
125100
{
126-
ChartTrackBallBehavior nearestTrackball = null;
101+
ChartTrackBallBehavior? nearestTrackball = null;
127102
double minDistance = double.MaxValue;
128103

129104
// Iterate through all trackball behaviors to find the nearest one
130-
foreach (var trackballBehaviour in SfChart.Behaviors)
105+
if (SfChart != null)
131106
{
132-
if (trackballBehaviour is ChartTrackBallBehaviorExt trackball)
107+
foreach (var trackballBehaviour in SfChart.Behaviors)
133108
{
134-
// Calculate the distance between the trackball and the touch point
135-
double distance = Math.Sqrt(Math.Pow(trackball.X - touchPoint.X, 2) + Math.Pow(trackball.Y - touchPoint.Y, 2));
136-
137-
// Update the nearest trackball if the current one is closer
138-
if (distance < minDistance)
109+
if (trackballBehaviour is ChartTrackBallBehaviorExt trackball)
139110
{
140-
minDistance = distance;
141-
nearestTrackball = trackball;
111+
// Calculate the distance between the trackball and the touch point
112+
double distance = Math.Sqrt(Math.Pow(trackball.X - touchPoint.X, 2) + Math.Pow(trackball.Y - touchPoint.Y, 2));
113+
114+
// Update the nearest trackball if the current one is closer
115+
if (distance < minDistance)
116+
{
117+
minDistance = distance;
118+
nearestTrackball = trackball;
119+
}
142120
}
143121
}
144122
}

0 commit comments

Comments
 (0)