Rick
Topic Author
Posts: 50
Joined: 26 Nov 2013, 15:35

Button click delegate for class method

08 Apr 2015, 02:42

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.
Button3 = uiRenderer->GetXAML()->FindName<Button>("Button3");
Button3->Click() += MakeDelegate()
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.
 
Rick
Topic Author
Posts: 50
Joined: 26 Nov 2013, 15:35

Re: Button click delegate for class method

08 Apr 2015, 03:37

OK had to dig but found some example code and got this sort of working.
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)
{
}
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.
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

Re: Button click delegate for class method

08 Apr 2015, 16:36

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:
UIElement::Event<RoutedEventHandler> Click(); 
And if you go to the RoutedEventHandler definition, it looks like:
typedef Delegate<void (BaseComponent*, const RoutedEventArgs&)> RoutedEventHandler;
So the signature of your Click event handler should be:
void OnButtonClick(BaseComponent* sender, const RoutedEventArgs& e);
 
Rick
Topic Author
Posts: 50
Joined: 26 Nov 2013, 15:35

Re: Button click delegate for class method

08 Apr 2015, 20:24

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