This can be done in several ways. The released Servy method is not bad and will do what you need. I would prefer to see that the Action<sting> passed as a parameter to the constructor and called callback , so it clears what it is used for, but this is only a preference.
Another way that does this pretty well is messaging. The MVVMLight Toolkit provides an excellent opportunity to perform tasks such as this.
Step 1: create a strongly typed message:
public class MyMessage : MessageBase {
Step 2: Determine where and when to post this post.
public class PublishMessage { public PublishMessage(){ } public void MyMethod() {
Setp 3: Now that you are sending a message, you should be able to receive this message:
public class MessageReceiver { public MessageReceiver() { Messenger.Default.Register<MyMessage>(this, message => Foo(message)); } public void Foo(MyMessage message) {
Joe brunscheon
source share