さて、今、グリッドをクリックすると、グリッド上のすべての「パス」を通過し、それらが楕円であるかどうか、マウスがそれらの上にあるかどうかを確認し、2つ選択されている場合は、距離を計算します。 ..しかし、グリッド上に50以上のポイントを取得した場合、ポイントをクリックしても何も起こりません....これを行うためのより効率的な方法はありますか?
これが私のコードです:
foreach (var x in GraphPanel.Children)
{
try
{
if (((Path)x).IsMouseOver && ((Path)x).Data.ToString() == "System.Windows.Media.EllipseGeometry")
{
listViewPoints.SelectedItems.Add(listViewPoints.Items[PointIndex]);
var converter = new System.Windows.Media.BrushConverter();
var brush = (System.Windows.Media.Brush)converter.ConvertFromString("#FFB1D100");
((Path)x).Stroke = brush;
((Path)x).StrokeThickness = 8;
if (listViewPoints.SelectedItems.Count == 2)
{
double diffX;
double diffY;
double ptAX = ((Points)listViewPoints.SelectedItems[0]).A;
double ptAY = ((Points)listViewPoints.SelectedItems[0]).B;
double ptBX = ((Points)listViewPoints.SelectedItems[1]).A;
double ptBY = ((Points)listViewPoints.SelectedItems[1]).B;
if (ptAX > ptBX)
{
diffX = ptAX - ptBX;
}
else
{
diffX = ptBX - ptAX;
}
if (ptAY > ptBY)
{
diffY = ptAY - ptBY;
}
else
{
diffY = ptBY - ptAY;
}
//the distance between the points = sqr/-diff in x squared + diff in y squared
double result = Math.Sqrt(Math.Pow(diffX,2) + Math.Pow(diffY,2));
CalculatedDistanceApart.Content = "Distance Apart: " + result.ToString() + "'";
}
}
if (((Path)x).Data.ToString() == "System.Windows.Media.EllipseGeometry")
{
PointIndex++;
}
}
catch { }
}