Hi,
I have a xamdatachart with a spline series. When the user clicks on the line in the chart, I need to get the item that was clicked and use it in my view model.
I have bound a command to the MouseLeftButtonDown event and as long as the user clicks on one of the marks on the line everything is fine, I get the item from the DataContext. But when the user clicks on the line between the marks I only get a SeriesDataContext which has no info about the item behind the value. How can I get the item when the line is clicked?
Regards,
Hilma
private void OnMouseLeftButtonDown(MouseEventArgs args) { var shape = (Shape)args.OriginalSource;MyItem item = null;
if (shape.DataContext is DataContext infragisticsDataContext) {Item = (MyItem)infragisticsDataContext.Item ; } else { var otherDataContext = (SeriesDataContext)shape.DataContext;// ??? How do I det MyItem now? }
this.MyMethod(item); }
Hello Hilma,
Thank you for posting. Instead of using OnMouseLeftButtonDown event , try to hook up SeriesMouseLeftButtonDown event off the chart and you can get the xValue and yValue through the event args.item.
Keep in mind when you click on the line ,you will get the closest dataitem of x and y.
Let me know if you have any question.
Thanks, that solved my problem!