I’m rebuilding a program to adhere to MVVM and so I’m trying to figure out little tricks to do things I did previously in the code-behind.
I’d like to be able to right-click on a selected series and add a point at that location. I’m doing this in my previous application but I’m not too sure the best route to take with the MVVM application.
I’m currently selecting a series with the SeriesSelectionModifier, but I’m also not sure if there’s a “SelectedSeries” property I can get from the modifier either.
Maybe a Trigger that detects a right mouse click on a selected series that calls a command to add the point?
Or is there just not a way to do this with the chart and I need to rely on subscribing to events?
Thanks!
Answer:
I created a property named SelectedSeries which looks like this…
public IRenderableSeries SelectedSeries
{
get
{
if (SciChart.SelectedRenderableSeries.Count > 0)
{
return SciChart.SelectedRenderableSeries[0];
} else
{
return null;
}
}
}
Then, I created a MouseRightButtonUp event to see if I right-clicked on SelectedSeries. If so, it adds a point. If I clicked on an existing point, it deletes that point.
private void _sciChart_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
{
if (SelectedSeries != null)
{
HitTestInfo hitTestToDelete = SelectedSeries.HitTest(rawPoint: MouseDownPosition, hitTestRadius: 10);
if (hitTestToDelete.IsHit == true)
{
// Do nothing if the first or last point is hit
if (hitTestToDelete.DataSeriesIndex == 0 || hitTestToDelete.DataSeriesIndex == SelectedSeries.DataSeries.Count - 1)
{
return;
}
// Delete point
DeletePoint(point: hitTestToDelete);
} else
{
// Add point if hitting series
HitTestInfo hitTestToAdd = SelectedSeries.HitTest(rawPoint: MouseDownPosition, hitTestRadius: 10, interpolate: true);
if (hitTestToAdd.IsHit == true)
{
// Add point
AddPoint(point: hitTestToAdd);
}
}
}
}
- Greg Knox asked 5 years ago
- last edited 5 years ago
-
Hey Greg, it would greatly improve our forums if you could add a short answer to your own question saying how you figured it out. Thanks!
-
Definitely! I should get a chance to do that later today or tomorrow.
- You must login to post comments
Please login first to submit.