Imports EgtUILib Public Class EgtMessageBoxVM Inherits VMBase #Region "FIELDS & PROPERTIES" Public Event m_CloseWindow(DialogResult As MessageBoxResult) Private m_sTitle As String = "" Public ReadOnly Property sTitle As String Get Return m_sTitle End Get End Property Private m_sMessage As String = "" Public ReadOnly Property sMessage As String Get Return m_sMessage End Get End Property Private m_Button As MessageBoxButton Private m_Icon As MessageBoxImage Public ReadOnly Property sIconSource As String Get Select Case m_Icon Case MessageBoxImage.Hand Return "\Resources\EgtMessageBox\Hand.png" Case MessageBoxImage.Question Return "\Resources\EgtMessageBox\Question.png" Case MessageBoxImage.Exclamation Return "\Resources\EgtMessageBox\Exclamation.png" Case MessageBoxImage.Asterisk Return "\Resources\EgtMessageBox\Asterisk.png" Case MessageBoxImage.Stop Return "\Resources\EgtMessageBox\Hand.png" Case MessageBoxImage.Error Return "\Resources\EgtMessageBox\Hand.png" Case MessageBoxImage.Warning Return "\Resources\EgtMessageBox\Exclamation.png" Case MessageBoxImage.Information Return "\Resources\EgtMessageBox\Asterisk.png" Case Else ' MessageBoxImage.None Return "" End Select End Get End Property Private m_ButtonList As New List(Of EgtMsgBoxButton) Public Property ButtonList As List(Of EgtMsgBoxButton) Get Return m_ButtonList End Get Set(value As List(Of EgtMsgBoxButton)) m_ButtonList = value End Set End Property #End Region ' FIELDS & PROPERTIES #Region "CONTRUCTORS" Sub New(sMessageBoxText As String) EgtMsgBoxButton.SetOwner(Me) m_sMessage = sMessageBoxText m_Button = MessageBoxButton.OK m_Icon = MessageBoxImage.None NotifyPropertyChanged(NameOf(ButtonList)) NotifyPropertyChanged(NameOf(sIconSource)) End Sub Sub New(sMessageBoxText As String, sCaption As String) MyClass.New(sMessageBoxText) m_sTitle = sCaption End Sub Sub New(sMessageBoxText As String, sCaption As String, Button As MessageBoxButton) MyClass.New(sMessageBoxText, sCaption) m_Button = Button Select Case m_Button Case MessageBoxButton.OK m_ButtonList.Add(New EgtMsgBoxButton(EgtMsgBoxButton.Types.OK)) Case MessageBoxButton.OKCancel m_ButtonList.Add(New EgtMsgBoxButton(EgtMsgBoxButton.Types.OK)) m_ButtonList.Add(New EgtMsgBoxButton(EgtMsgBoxButton.Types.CANCEL)) Case MessageBoxButton.YesNoCancel m_ButtonList.Add(New EgtMsgBoxButton(EgtMsgBoxButton.Types.YES)) m_ButtonList.Add(New EgtMsgBoxButton(EgtMsgBoxButton.Types.NO)) m_ButtonList.Add(New EgtMsgBoxButton(EgtMsgBoxButton.Types.CANCEL)) Case MessageBoxButton.YesNo m_ButtonList.Add(New EgtMsgBoxButton(EgtMsgBoxButton.Types.YES)) m_ButtonList.Add(New EgtMsgBoxButton(EgtMsgBoxButton.Types.NO)) End Select NotifyPropertyChanged(NameOf(ButtonList)) End Sub Sub New(sMessageBoxText As String, sCaption As String, Button As MessageBoxButton, Icon As MessageBoxImage) MyClass.New(sMessageBoxText, sCaption, Button) m_Icon = Icon NotifyPropertyChanged(NameOf(sIconSource)) End Sub Sub New(sMessageBoxText As String, sCaption As String, Button As MessageBoxButton, Icon As MessageBoxImage, DefaultResult As MessageBoxResult) MyClass.New(sMessageBoxText, sCaption, Button, Icon) Dim DefaultBtn As EgtMsgBoxButton = m_ButtonList.FirstOrDefault(Function(x) (x.Type = EgtMsgBoxButton.Types.OK AndAlso DefaultResult = MessageBoxResult.OK) OrElse (x.Type = EgtMsgBoxButton.Types.CANCEL AndAlso DefaultResult = MessageBoxResult.Cancel) OrElse (x.Type = EgtMsgBoxButton.Types.YES AndAlso DefaultResult = MessageBoxResult.Yes) OrElse (x.Type = EgtMsgBoxButton.Types.NO AndAlso DefaultResult = MessageBoxResult.No)) If Not IsNothing(DefaultBtn) Then DefaultBtn.SetIsDefault(True) End If NotifyPropertyChanged(NameOf(ButtonList)) End Sub #End Region ' CONTRUCTORS #Region "METHODS" Friend Sub CloseWindow(DialogResult As MessageBoxResult) RaiseEvent m_CloseWindow(DialogResult) End Sub #End Region ' METHODS End Class Public Class EgtMsgBoxButton Inherits VMBase #Region "FIELDS & PROPERTIES" Public Enum Types As Integer OK = 1 CANCEL = 2 YES = 3 NO = 4 End Enum Private Shared Owner As EgtMessageBoxVM Private m_Type As Types Public ReadOnly Property Type As Types Get Return m_Type End Get End Property Private m_sMessage As String Public ReadOnly Property sMessage As String Get Return m_sMessage End Get End Property Private m_bIsDefault As Boolean = False Public ReadOnly Property bIsDefault As Boolean Get Return m_bIsDefault End Get End Property Friend Sub SetIsDefault(bValue As Boolean) m_bIsDefault = bValue End Sub ' Definizione comandi Private m_cmdCommand As ICommand #End Region ' FIELDS & PROPERTIES #Region "CONTRUCTORS" Sub New(Type As Types) m_Type = Type Select Case m_Type Case Types.OK m_sMessage = EgtMsg(35001) ' Ok Case Types.CANCEL m_sMessage = EgtMsg(35002) ' Cancel Case Types.YES m_sMessage = EgtMsg(35003) ' Yes Case Types.NO m_sMessage = EgtMsg(35004) ' No End Select End Sub Sub New(Type As Types, bIsDefault As Boolean) MyClass.New(Type) m_bIsDefault = bIsDefault End Sub #End Region ' CONTRUCTORS #Region "METHODS" Friend Shared Sub SetOwner(value As EgtMessageBoxVM) Owner = value End Sub #End Region ' METHODS #Region "COMMANDS" #Region "Command" Public ReadOnly Property Command_Command As ICommand Get If m_cmdCommand Is Nothing Then m_cmdCommand = New Command(AddressOf Command) End If Return m_cmdCommand End Get End Property Public Sub Command() Select Case m_Type Case Types.OK Owner.CloseWindow(MessageBoxResult.OK) Case Types.CANCEL Owner.CloseWindow(MessageBoxResult.Cancel) Case Types.YES Owner.CloseWindow(MessageBoxResult.Yes) Case Types.NO Owner.CloseWindow(MessageBoxResult.No) End Select End Sub #End Region ' Ok #End Region ' COMMANDS End Class