'Hittest why does program shut down
I am trying to create a easy game where the user is supposed to hit on a rectangle in timely maner. I tried with hittestresult which made it possible to add points and create a new rectangle when it gets clicked on. But every time you click on any other space of the canvas the program shuts down. why does this happen. I am just a beginner so excuse my bad programming skills. Here is my method containing the issue:
private void spielfeld_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
// Retrieve the coordinate of the mouse position.
Point pt = e.GetPosition((UIElement)sender);
// Perform the hit test against a given portion of the visual object tree.
HitTestResult treffer = VisualTreeHelper.HitTest(spielfeld, pt);
if (treffer != null)
{
string name = ((Shape)(treffer.VisualHit)).Name;
if (name == "fangbutton")
{
punkte++;
punktAnzeige.Content = punkte;
catchme.Entfernen(spielfeld);
catchme.Anzeige(spielfeld);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
