Simple way of showing Msgbox and Dialogs in WPF MVVM

I know that MVVM purists say that you should not use messageboxes and Dialogs in a MVVM application , however as a business developer you must sometimes blok the GUI to let the user pick an item or confirm there actions . After some discussions in the comunity i decided to show y

 
 
 
 
 
4 Star
(1)
3,566 times
Add to favorites
3/26/2011
E-mail Twitter del.icio.us Digg Facebook

Solution explorer

VB.NET
'Michel Posseth 26-03-2011
'Base class for MVVM viewmodel
Imports System
Imports System.ComponentModel
Imports System.Diagnostics
Namespace VBDC.ViewModel

    ''' <summary>
    ''' Base class for all ViewModel classes in the application.
    ''' It provides support for property change notifications 
    ''' and has a DisplayName property.  This class is abstract.
    ''' </summary>
    Public MustInherit Class ViewModelBase
        Inherits ObservableObject
        Implements IDisposable
        Implements IMsgBoxSendRec

#Region "Constructor"
        Protected Sub New()
            MyBase.new()
        End Sub
#End Region ' Constructor
        Private _DisplayName As String
        Public Overridable Property DisplayName() As String
            Get
                Return _DisplayName
            End Get
            Set(ByVal value As String)
                If value.Equals(_DisplayName) Then Return
                _DisplayName = value
                OnPropertyChanged("DisplayName")
            End Set
        End Property
#Region "IDisposable Members"

        ''' <summary>
        ''' Invoked when this object is being removed from the application
        ''' and will be subject to garbage collection.
        ''' </summary>
        Public Sub Dispose() Implements IDisposable.Dispose
            Me.OnDispose()
        End Sub

        ''' <summary>
        ''' Child classes can override this method to perform 
        ''' clean-up logic, such as removing event handlers.
        ''' </summary>
        Protected Overridable Sub OnDispose()
        End Sub

#If DEBUG Then
        ''' <summary>
        ''' Useful for ensuring that ViewModel objects are properly garbage collected.
        ''' </summary>
        Protected Overrides Sub Finalize()
            Dim msg As String = String.Format("{0} ({1}) ({2}) Finalized", Me.GetType().Name, Me.DisplayName, Me.GetHashCode())
            System.Diagnostics.Debug.WriteLine(msg)
        End Sub
#End If

#End Region ' IDisposable Members
#Region "Messagebox and window"
        Public Event eShowMsgbox(Txt As String, Caption As String, ButtonStyle As System.Windows.MessageBoxButton, ImageStyle As System.Windows.MessageBoxImage, myWindow As System.Windows.Window, sender As Object) Implements IMsgBoxSendRec.eShowMsgbox
        Private _MsgboxResult As System.Windows.MessageBoxResult?
        Public Property MsgboxResult As System.Windows.MessageBoxResult? Implements IMsgBoxSendRec.MsgboxResult
            Get
                Return _MsgboxResult
            End Get
            Set(value As System.Windows.MessageBoxResult?)
                _MsgboxResult = value
            End Set
        End Property
        Private _Window As Window
        Public Property myWindow As System.Windows.Window Implements IMsgBoxSendRec.myWindow
            Get
                Return _Window
            End Get
            Set(value As System.Windows.Window)
                _Window = value
            End Set
        End Property
        Friend Sub RaiseEventShowMsgbox(Txt As String, Caption As String, ButtonStyle As System.Windows.MessageBoxButton, ImageStyle As System.Windows.MessageBoxImage, myWindow As System.Windows.Window, sender As Object)
            RaiseEvent eShowMsgbox(Txt, Caption, ButtonStyle, ImageStyle, myWindow, sender)
        End Sub
#End Region
    End Class


End Namespace