In a previous question I built an event
class, public class SetObjectEvent : PubSubEvent<MyObject> { }
, which is working perfectly fine. However, I want to do the same with methods now, so I'll have to extend something else than PubSubEvent<>
(?)
While browsing through le bigue o'le interwebz, most question like "How do I call a method from another ViewModel through this ViewModel", people refer to dependencies or commands, which are fine solutions I've used in the past. But in this specific case, neither of those work because I'm dealing with a case where the Child of it's Parent's Sibling needs to be called by said Sibling. Because the Parent does not (and can not) know of it's child's existance other than the child calling for some properties every now and then, I figured using an EventAggregator would be the best possible solution, unless someone has a better idea of course.
So, Concretely, my question is; With what should I replace PubSubEvent<>
in my SetObjectEvent
to get the similar version CallMethodEvent : ?x?x?x? { }
?
Not sure if I completely understand your problem, because the solution is a bit trivial:
EventAggregator.GetEvent<MyEvent>().Subscribe( MyMethod );
with
public class MyEvent : PubSubEvent
{
}
This executes MyMethod
each time MyEvent
is published, isn't that what the whole event mechanism is for?
I guess, you could also publish a method as payload, if you want to execute a method defined by the publisher in the context of each subscriber, but I haven't come up with a use case for that yet :-)