Message mediator

Topics: Questions
Oct 12, 2012 at 10:07 PM
Edited Oct 12, 2012 at 10:16 PM

Hi everyone,


I try to implement the message mediator so a viewmodel can communicate with a view (code behind) but I end up with an error so I guess I am missing something.

here is my viewmodel

 public class HomeWindowViewModel : WindowViewModelBase
        private FileSystemWatcher watcher;
        private IMessageMediator mediator = MessageMediator.Default;


        /// Initializes a new instance of the  class.

        public HomeWindowViewModel():base()
            CheckMessagesCommand = new Command(OnCheckMessagesCommandExecute);

public Command CheckMessagesCommand { get; private set; }

        private void OnCheckMessagesCommandExecute()
            mediator.SendMessage("test", "New Message");

and here is the code behind I would to receive the message 

public partial class MainWindow : DataWindow
        /// <summary>
        /// Initializes a new instance of the <see cref="MainWindow"/> class.
        /// </summary>
        public MainWindow()
            : base(DataWindowMode.Custom)

        [MessageRecipient(Tag = "New Message")]
        public void ShowBallon(string message)
            TaskIcon.ShowBalloonTip("Email Received", "test", BalloonIcon.Info);


But when I launch the application I get this error:"The type 'Catel.Messaging.IMessageMediator' is not registered, not even in an external container"
How can I register the mediator so it can send a message when the command is fired?
Thank you

Oct 14, 2012 at 7:12 PM

If you are using Catel 3.3, types are not yet autoregistered. To make a long story short, in Catel 3.3 and before, types are registered in the static ctor of the first view model instance. However, because you use it in the window, it is not yet registered.

You have 2 options:

1) Use the latest pre-release of Catel, it automatically registers everything in the ServiceLocator when the module (assembly) is loaded

2) Register it yourself manually in the application startup:

Catel.IoC.ServiceLocator.Instance.Register<IMessageMediator, MessageMediator>();

Oct 18, 2012 at 9:37 PM

Thanks for your answer.

I tried registering it in the application start up using the 2) proposed solution but get a different error:

"PixelShader must be set on ShaderEffect."


Does that error related to Catel framework?

I will try using the pre release of Catel and see if I end up with the same error.

Thank you


Oct 18, 2012 at 9:38 PM

This was an issue in the last official build of Catel. Try the latest pre-release please.

Oct 18, 2012 at 10:14 PM

Good news I tried with the pre release as you advised and it works the message is correctly catch in the view code behind.


Thanks again for you time