hello,I used your extension ChartCrosshairBehaviors for a horizontal bar in xamdatachart.
But there is a bug:
explanation:
My Xamdatachart has an Y axis. When the mouse pointer enters the area of Xamdatachart from the side of Y axis the exention causes ChartCrosshairBehaviors a runtime error:
Error message:
Index was out of range. Must be non-negative and less than the size of the collection.Parameter name: index
Line Causes error in ChartCrosshairVisibilityBehavior.cs:
bool uninitialized = lines[0].X1 == 0.0 && lines[0].X2 == 0.0 && lines[1].X1 == 0.0 && lines[1].X2 == 0.0;
Remarks:
I think because the Y axis is part of the XamDatachart and when the mouse pointer enters from the side of Y axis, the Event (chart.MouseEnter + = OnChartMouseEnter) is caused. At this time the xamdatachart in question has not yet lines. what causes the bug.
Thank you for helping me find a solution.
Regards.
Hello Anis,
I am just checking if you got this worked out or you still require any assistance or clarification on the matter.
Hello Stefan,
The problem has been resolved.
this is the code:
public void ChartMouseEnter(object sender) { XamDataChart chart = sender as XamDataChart; if (_first && chart != null) { _first = false; var crosshairs = from line in chart.VisualDescendants() where line is Line && (line as Line).Style == chart.CrosshairLineStyle select line as Line; List<Line> lines = crosshairs.ToList();
bool uninitialized = lines.Count == 0 || (lines[0].X1 == 0.0 && lines[0].X2 == 0.0 && lines[1].X1 == 0.0 && lines[1].X2 == 0.0);
if (uninitialized || lines.Count == 1) { _first = true; chart.MouseMove += OnChartMouseEnter; return; }
if (lines[0].X1 == lines[0].X2) { _vertical = lines[0]; _horizontal = lines[1]; } else { _vertical = lines[1]; _horizontal = lines[0]; }
if (!this.ShowHorizontalCrosshair) { MakeInvisible(chart, _horizontal); } if (!this.ShowVerticalCrosshair) { MakeInvisible(chart, _vertical); }
chart.MouseMove -= OnChartMouseEnter; } }
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.