Deprecating the DialogMessage

.NET, MVVM, Phone, Silverlight, Technical stuff, Windows 8, Windows Phone, Work, WPF
13 Comments

One change you will notice when you install MVVM Light V4.3.31 is that I marked the DialogMessage class as Obsolete.

The DialogMessage class is one of the built in message classes in the MVVM Light Messaging namespace. When sent by the Messenger to a view element (Window, Page, etc), it carries information that can be used by the recipient to display a message to the user. It also has a callback to pass the result (OK, Cancel, etc) back to the caller for handling.

DialogMessage is an old class from MVVM Light, it was already there in the first versions, when the toolkit was only available for WPF. It has a few “youth issues” because of that, and if I had to do it again, I wouldn’t include this class anymore. The main issue with it is that it uses “view enumerations” such as MessageBoxButton and MessageBoxResult. In fact, because of these issues I removed DialogMessage from the Windows Store version of MVVM Light already. The differences between WPF, Silverlight and Windows Phone/Silverlight on one hand, and Windows Store on the other hand are too big and made this class unmanageable. As a result, this breaks cross platform compatibility when you want to use your viewmodels in Windows Store apps too.

Marking the class as obsolete means that you should transition to another implementation. I prefer the “dialog service” implementation to display messages to the user and pass the result to the caller. More information about the IDialogService implementation as well as a sample can be found in one of my MSDN article magazines.

Coming up soon I will publish a cross platform implementation of DialogService which I use on various platforms, including Xamarin. It’s not quite ready yet, and I want to spend more time on this first. For now, you don’t need to worry too much about the Obsolete warning, as the DialogMessage class will continue to work like before. Eventually however, it will be removed from MVVM Light.

Stay tuned to my Twitter feed and to this blog for announcement when the cross platform DialogService sample will be ready.

Happy coding
Laurent

GalaSoft Laurent Bugnion
Laurent Bugnion (GalaSoft)
Share on Facebook
 

13 Responses to “Deprecating the DialogMessage”

  1. Curt Says:

    “For now, you don’t need to worry too much about the Obsolete warning”

    FYI, many devs tell our build tools to treat warnings as errors. It saves us from not seeing warnings that really matter.

  2. lbugnion Says:

    If they treat warnings as error, then i would recommend moving code to the new recommended way of doing things. There is unfortunately no better way to gently deprecate a class or a method in .net at least to my knowledge.

  3. lbugnion Says:

    Also want to point out the possibility to get the source code from Codeplex and to use the DialogMessage class directly in your code. That would be an easy fix to the Warning problem if you decide to continue with DialogMessage in spite of the problems mentioned in this blog post.

    Cheers
    Laurent

  4. Karen Says:

    The code sample for the linked MSDN article does not exist, it would really be nice to download it and take a look.

  5. lbugnion Says:

    i know, i contacted the mdsn people but no reply yet. Sorry for the inconvenience.

  6. Goran Says:

    Hi,

    if I understood correctly, DialogMessage has been marked obsoleted, and MVVMLight does not provide a messenger class anymore, so we need to implement one manually?

    P.S. The link to website now works, but download link in it does not.
    Regards,
    Goran

  7. Mansoor Says:

    In my case, I found it easier to resort to the following pragma directive to rid of the annoying obsolescence warning filling my error list:

    #pragma warning disable 0618
    #pragma warning restore 0618

    http://stackoverflow.com/questions/968293/c-sharp-selectively-suppress-custom-obsolete-warnings

  8. lbugnion Says:

    Hi,

    I am working on a new series of blogs that will give you answers on how to do navigation and dialogs in MVVM Light applications. The first post of this series will follow in a few days, and then it will take a while until I post everything.

    Cheers
    Laurent

  9. Alex Says:

    Hi Laurent, am I understanding correctly that future versions of the toolkit will provide an implementation of DialogService? I am trying to understand whether I should convert to my own or simply wait until you have a standardized implementation available.

  10. lbugnion Says:

    Hi,

    I am working on a series of articles about NavigationService and DialogService. It is possible that I include these in MVVM Light at some point, but I will be looking for feedback about this. At this time I am rather thinking to include them in the project templates.

    Cheers
    Laurent

  11. TheCountess Says:

    hi laurent,

    i would just like to point out that the code sample for the msdn article you linked to in this post is no longer available. i seem to be missing something when i try to implement it from just the article.

  12. lbugnion Says:

    Hi,

    Sorry about that. We had some issues with the code samples at MSDN recently. I am traveling now but i will check asap.

    cheers
    Laurent

  13. Klas Says:

    Hi!
    Would be great if all the MSDN samples for your articles could be reposted somewhere else unless yo get them to republish them.

Leave a Reply