Basp
Topic Author
Posts: 22
Joined: 08 May 2014, 10:09

[Unity] Casting sender to Button in its Click handler

27 Jun 2014, 22:52

If I define a button and add an event handler for its Click event, I get a method that has a sender parameter of type BaseComponent, and an e parameter of type RoutedEventArgs. Since I may have multiple buttons that all use this event handler, I want to figure out which button has fired the event. In WPF, I'd just cast the sender argument to a Button:
var button = sender as Button;
However, this doesn't work in NoesisGui. I can't seem to cast the BaseComponent to anything, and can't really do anything with the sender argument.

How do get a reference to the Button that fired the click event from the event handler?
 
wckdspn
Posts: 67
Joined: 18 Aug 2012, 23:14

Re: [Unity] Casting sender to Button in its Click handler

27 Jun 2014, 22:58

You can call on the BaseComponent As<Button>();
 
Basp
Topic Author
Posts: 22
Joined: 08 May 2014, 10:09

Re: [Unity] Casting sender to Button in its Click handler

29 Jun 2014, 10:04

Wow, I can't believe it was that simple. Thanks!
 
Weltista
Posts: 11
Joined: 14 Jun 2014, 23:52

Re: [Unity] Casting sender to Button in its Click handler

29 Jun 2014, 18:19

Plus one -- very helpful, thanks. (Had to use Noesis.Button.GetIsMouseOver() before that).
 
User avatar
jsantos
Site Admin
Posts: 3925
Joined: 20 Jan 2012, 17:18
Contact:

Re: [Unity] Casting sender to Button in its Click handler

01 Jul 2014, 22:46

We are aware that this is not the standard way to cast in c#. It should work with the 'as' keyword. It is something we have in our To Do list.

Who is online

Users browsing this forum: Ahrefs [Bot] and 41 guests