diesel76
Topic Author
Posts: 2
Joined: 20 Feb 2015, 20:22

get the event's object

21 Feb 2015, 11:19

I have an event function and i want to use this for multiple objects. So in the event function i try to get the object source of the event to do the right action.

public void changed(BaseComponent c, Noesis.RoutedEventArgs args)
{
mybox = new ComboBox ();

"this is not a noesis code but it's like that in flash it's just for the example it doesn't work in noesis of course":
mybox = args as Target ();

String str = mybox.GetSelectedItem ().AsString();
Debug.Log(str);
}
 
User avatar
Scherub
Posts: 141
Joined: 06 May 2014, 20:53
Contact:

Re: get the event's object

23 Feb 2015, 04:20

If I understand you right and you just want to use the same method for the event handler of multiple framework elements such as ComboBox, I think in NoesisGUI v1.1 it should look like this:
public void changed(BaseComponent sender, Noesis.RoutedEventArgs args)
{
	var myBox = sender.As<ComboBox>();

	if (myBox == _comboBox1)
	{
		// do whatever you want
	}
	else if (myBox == _comboBox2)
	{
		// do whatever you want
	}
}
But this would be considered a bad design in WPF. You should also have a look at bindings as these make everything more flexible and easier to use.

But perhaps I've got you completely wrong. :)
 
User avatar
sfernandez
Site Admin
Posts: 1911
Joined: 22 Dec 2011, 19:20

Re: get the event's object

23 Feb 2015, 17:15

Thanks for your help here Scherub ;)

diesel76, does the example by Scherub explain what you are looking for?

Who is online

Users browsing this forum: TheMPC and 2 guests