Button click delegate for class method
I'm looking to make a C++ class function to handle a button click event (and eventually other things). Is there somewhere to see the event signatures to handle this and how to set this up? I'm not sure how to setup the C++ callback member method and how to assign it. I'm thinking it has something to do with the below but I'm not finding any examples that do this.
Also I'm trying to add this to the class I'm doing the above code in. Some possibly some sort of:
Button3->Click() += MakeDelegate(this, App::Button3_OnClick);
But this doesn't work.
Code: Select all
Button3 = uiRenderer->GetXAML()->FindName<Button>("Button3");
Button3->Click() += MakeDelegate()
Button3->Click() += MakeDelegate(this, App::Button3_OnClick);
But this doesn't work.
Re: Button click delegate for class method
OK had to dig but found some example code and got this sort of working.
The strange thing is this event is firing when I just put the mouse over the control. I'm not clicking at all.
[EDIT]
Ah, it's a hover button I was over! All good.
Code: Select all
Gui::Button* Button3;
void Button3_OnClick(BaseComponent* sender, const RoutedEventArgs& e);
Button3 = uiRenderer->GetXAML()->FindName<Button>("Button3");
Button3->Click() += MakeDelegate(this, &App::Button3_OnClick);
void App::Button3_OnClick(BaseComponent* sender, const RoutedEventArgs& e)
{
}
[EDIT]
Ah, it's a hover button I was over! All good.
-
sfernandez
Site Admin
- Posts: 2983
- Joined:
Re: Button click delegate for class method
You can find the signature of each event by looking at the typedef of the event handler.
For example, the Button.Click event is defined as:
And if you go to the RoutedEventHandler definition, it looks like:
So the signature of your Click event handler should be:
For example, the Button.Click event is defined as:
Code: Select all
UIElement::Event<RoutedEventHandler> Click();
Code: Select all
typedef Delegate<void (BaseComponent*, const RoutedEventArgs&)> RoutedEventHandler;
Code: Select all
void OnButtonClick(BaseComponent* sender, const RoutedEventArgs& e);
Re: Button click delegate for class method
Thank you for the explanation. I'm person who learns better with english explanations vs weeding through code. This helped a lot.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 67 guests