[Unity] Casting sender to Button in its Click handler
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:
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?
Code: Select all
var button = sender as Button;
How do get a reference to the Button that fired the click event from the event handler?
Re: [Unity] Casting sender to Button in its Click handler
You can call on the BaseComponent As<Button>();
Re: [Unity] Casting sender to Button in its Click handler
Wow, I can't believe it was that simple. Thanks!
Re: [Unity] Casting sender to Button in its Click handler
Plus one -- very helpful, thanks. (Had to use Noesis.Button.GetIsMouseOver() before that).
Re: [Unity] Casting sender to Button in its Click handler
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