0
MSDN上的這個頁面代表了一個使用HitTest的例子,這個例子在概念上是清晰的,但是我沒有得到的是C#代碼指向hitResultsList的列表。我試圖將其聲明爲List:使用HitTest中的列表
List<myShapeClass> hitResultsList = new List<myShapeClass>();
但是,我收到了類型轉換錯誤。任何幫助將不勝感激。問題是我應該用什麼樣的List來進行HitTesting?
代碼是在這裏:
// Respond to the right mouse button down event by setting up a hit test results callback.
private void OnMouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
// Retrieve the coordinate of the mouse position.
Point pt = e.GetPosition((UIElement)sender);
// Clear the contents of the list used for hit test results.
hitResultsList.Clear();
// Set up a callback to receive the hit test result enumeration.
VisualTreeHelper.HitTest(myCanvas, null,
new HitTestResultCallback(MyHitTestResult),
new PointHitTestParameters(pt));
// Perform actions on the hit test results list.
if (hitResultsList.Count > 0)
{
Console.WriteLine("Number of Visuals Hit: " + hitResultsList.Count);
}
}
感謝。