Page 1 of 1

get the event's object

Posted: 21 Feb 2015, 11:19
by diesel76
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);
}

Re: get the event's object

Posted: 23 Feb 2015, 04:20
by Scherub
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. :)

Re: get the event's object

Posted: 23 Feb 2015, 17:15
by sfernandez
Thanks for your help here Scherub ;)

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