Messenger en MVVM Light? ¡Cuidado con los mensajitos!

Si una vista coge un mensaje y luego se cierra, DESREGISTRA LA VISTA! porque si no lo haces, se queda recibiendo mensajines everytime Risa y es muy muy jodido de encontrar la razón.

Aquí está lo que hay que hacer, fiery man:

public NewDocumentDialog()

       {

           InitializeComponent();

           Unloaded += (sender, args) => Messenger.Default.Unregister<QDFPage>(this);

 

           Messenger.Default.Register<QDFPage>(this, OnMessageReceived);   

       }

 

       private void OnMessageReceived(QDFPage page)

       {

           SetPage(page);

           DialogResult = true;

       }

 

Y esto de más abajo es la respuesta que no me han dejado publicar en StackOverflow… que quede aquí reflejada: http://stackoverflow.com/questions/7036873/when-to-dispose-viewmodel-in-mvvm-light

Thanks, thanks a lot! I was using a widow with ShowDialog. This view has a viewmodel that communicates success using the Messenger. When opened the second time, when setting the DialogResult = true, it stated “DialogResult can be set only after Window is created and shown as dialog.”

The fact is that I the older instances of the window didn’t unregister from the Messenger! They were still receiving messages! show the attempts to set their DialogResult failed, logically.

It was hard to find, but it’s FIXED!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s