[英]OnClick Event for Rectangle with C#
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. 这些矩形是在启动应用程序时使用C#创建的。
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. 我知道如何在XAML的帮助下创建OnClick事件,但是我的问题是我不知道如何在应用程序启动后执行通过C#创建的事件。
There is no Click
event on Rectangle
in System.Windows. System.Windows中的Rectangle
上没有Click
事件。 You can use MouseLeftButtonDown
event like: 您可以使用MouseLeftButtonDown
事件,例如:
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)
{
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.