WindowsPhoneGeek

WPAppInfo

Login | Join (Why?)

rss rss rss
logo

Behavior to show a MessageBox from a ViewModel

2/22/2012

source: Joost van Schaik`s blog

Since I am a very lazy programmer and I not always want to register or define services and whatnot for showing a simple message I created this extremely simple behavior for showing a MessageBox from a ViewModel. I wrote the code for Windows Phone 7, but I suppose it could be used in Silverlight as well.

The behavior itself is as simple as this:

using System.Windows;
using System.Windows.Interactivity;

namespace Wp7nl.Behaviors
{
  public class MessageBoxDisplayBehavior : Behavior<FrameworkElement>
  {
    public const string MessagePropertyName = "Message";

    public string Message
    {
      get { return (string)GetValue(MessageProperty); }
      set { SetValue(MessageProperty, value); }
    }

 ...Read more

You can also follow us on Twitter @winphonegeek

Comments

Add comment to 'Behavior to show a MessageBox from a ViewModel'

Comment

Our Top Articles & Free books

Our Top Tips & Samples