How to add a click handler to a WPF Button in C++/CLR?
In C#, I can do (*):
Button b = new Button();
b.Click += ButtonOnClick;
:
void ButtonOnClick(object sender, RoutedEventArgs e)
{
// do something
}
But in C++/CLI I can't do:
Button ^ b = gcnew Button();
b->Click += ButtonOnClick;
:
void ButtonOnClick(Object ^ sender, RoutedEventArgs ^ e)
{
// do something
}
I get a compiler error complaing about the += ButtonOnClick: 2>.\blub.cpp(108) : error C3867: 'MyListBoxItem::ButtonOnClick': function call missing argument list; use '&MyListBoxItem::ButtonOnClick' to create a 开发者_Go百科pointer to member
(The tip the compiler gives me doesn't work because it isn't a static method.)
What is the equivalent of (*) in C++/CLI ?
Thx Marc
try
b->Click += MAKE_DELEGATE( System::EventHandler, ButtonOnClick );
b->Click += gcnew System::EventHandler(this, &ButtonOnClick);
精彩评论