-1

Question may be phrased wrong and I'm sorry for that.

I have a grid filled with with rectangles. These rectangles are created with C# when the application is started.

I know how to create OnClick Event with the help of XAML, however, my problem is that I don't know how to do one that's created via C# after application has started.

IronCanTaco
  • 101
  • 1
  • 12

1 Answers1

2

There is no Click event on Rectangle in System.Windows. You can use MouseLeftButtonDown event like:

Rectangle rectangle = new Rectangle();
//initialize properties
//Add Event like
rectangle.MouseLeftButtonDown += rectangle_MouseLeftButtonDown;

and the event handler could be:

void rectangle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{

}
Habib
  • 219,104
  • 29
  • 407
  • 436