tags:

views:

50

answers:

1

HI, I try to understant how to send a message directly to a speciciel Target. I got a small SL projet and and a dunmmy class named class1. I register in the class constructor and listenig for all string type message.

public class Class1
{
    public Class1()
    {
        Messenger.Defaut.Register<String>(this, f => { TraiteMessage(f); });
    }

    public void TraiteMessage(string sMessage)
    {
        MessageBox.Show("Class1:" + sMessage);
    }
}

Now I send the message like this:

Messenger.Defaut.Send<String, Class1>("test message");

The message do not reach the target. When I look into the internal source code of the MVVM light i can see that the test are done like: item.Action.Target.GetType() == messageTargetType but in fact the messageTargetType are set to: MyProejet.Class1 but the item.Action.Target.GetType() return something like: {System.Collections.Generic.Dictionary2System.Type,System.Collections.Generic.List1[SLDuninLib.Messages.Avise+WeakActionAndToken]]} System.Type {System.RuntimeType}

what do i do wrong? Thanks for your help

A: 

Is an instance of Class1 created anywhere? If not, then it never registers to receive any messages.

You can easily test this by putting a breakpoint on the line of code that registers to receive the message in the Class1 constructor.

I tested your code and it works when I have the message registration in another view model, but this is because any view models in the ViewModelLocator are created as soon as the App.xaml is loaded.

Matt Casto
Yes, the class1 are instanciate in the MainPage.xaml.ca load event. For testing purpose.
Pierre