views:

289

answers:

2

I'm using the MVVM Light Toolkit. I could not find any Ctor of Messenger or Notification class to send a empty message.

ViewModel1:

 private int _selectedWeeklyRotation;
    public int SelectedWeeklyRotation
    {
        get { return _selectedWeeklyRotation; }
        set
        { 
            if(_selectedWeeklyRotation == value)
                return;

            _selectedWeeklyRotation = value;
            this.OnPropertyChanged("SelectedWeeklyRotation");
            if(value > 1)
                Messenger.Default.Send();                     
        }
    }

ViewModel2:

Ctor:

Messenger.Default.Register(this, CreateAnotherTimeTable); 

private void CreateAnotherTimeTable()
{

}

I just need to send a Notification to another ViewModel, no sending of data at all.

Is that possible with MVVM Light Toolkit library?

A: 

Hi, I don't think that it is possible and frankly I don't see the point of having that kind of message. You could just as well send a string "SelectedWeeklyRotation". It seems strange to have an empty message that has some kind of meaning as you increase the number of broadcast messages - and receivers in your application.

In the version of MVVM Light that I'm using it is not even possible to send an empty message.

However I did see a method in the ViewModelBase that is :

// Update bindings and broadcast change using GalaSoft.MvvmLight.Messenging
RaisePropertyChanged(MyPropertyPropertyName, oldValue, value, true);

This might be of interest for you.

@karinplooks interesting, have you found any sample for that method? I can not find any info/sample project about the usage of that event.
msfanboy
A: 

There really isn't a way to accomplish this and in someways defies the point of the messenger class. I didn't want to write a your doing it wrong post, but I feel I am stuck. The way the messenger class works is that you have two parties that both subscribe to the same concept, its an observer model. Without that similar concept or message there really isn't a way to tie the two objects together. The generic message whether a simple string or custom message act as the meeting point of the Subscribing and Publishing classes.

If the ViewModel publishing knows the type of ViewModel its trying to Send to it could...

Messenger.Default.Send<Type>(typeof(ViewModelToSendTo);

This would act as a very simple interaction point, you also wouldn't have to create a custom class. Some purist may have an issue with this approach as it couples the publishing class to the subscriber.

Agies