# DXMessageBoxService | WPF Controls | DevExpress Documentation

The [DXMessageBoxService](/WPF/DevExpress.Xpf.Core.DXMessageBoxService) is an [IMessageBoxService](/CoreLibraries/DevExpress.Mvvm.IMessageBoxService) implementation that uses the [ThemedMessageBox](/WPF/DevExpress.Xpf.Core.ThemedMessageBox) control to show messages.

![DXMessageBox Collage](/WPF/images/dxmessagebox-collage18666.png)

Note

Use the [UseThemedWindowInServices](/CoreLibraries/DevExpress.Xpf.Core.CompatibilitySettings.UseThemedWindowInServices) compatibility property to use the [DXMessageBox](/WPF/DevExpress.Xpf.Core.DXMessageBox) control in the `DXMessageBoxService`.

The following code sample demonstrates how to use the [DXMessageBoxService](/WPF/DevExpress.Xpf.Core.DXMessageBoxService) and perform an action based on the clicked message box button:

![](/WPF/images/MessageBoxService_Example.png)

- XAML

<section id="tabpanel_jqfOlQXRPB_tabid-xaml" role="tabpanel" data-tab="tabid-xaml">
<pre><code class="lang-xaml">&lt;Window ...
        xmlns:dx=&quot;http://schemas.devexpress.com/winfx/2008/xaml/core&quot; 
        xmlns:dxmvvm=&quot;http://schemas.devexpress.com/winfx/2008/xaml/mvvm&quot;
        DataContext=&quot;{dxmvvm:ViewModelSource Type=local:ViewModel}&quot;&gt;
    &lt;dxmvvm:Interaction.Behaviors&gt;
        &lt;dx:DXMessageBoxService/&gt;
    &lt;/dxmvvm:Interaction.Behaviors&gt;

    &lt;dx:SimpleButton Content=&quot;{Binding ButtonText}&quot;
                     Command=&quot;{Binding SaveConfirmationCommand}&quot;/&gt;
&lt;/Window&gt;
</code></pre></section>

- C#
- VB.NET

<section id="tabpanel_jqfOlQXRPB-1_tabid-csharp" role="tabpanel" data-tab="tabid-csharp">
<pre><code class="lang-csharp">public class ViewModel : ViewModelBase {
    public virtual string ButtonText { get; set; } = &quot;Save Changes Button&quot;;

    IMessageBoxService MessageBoxService { get { return GetService&lt;IMessageBoxService&gt;(); } }

    [Command]
    public void SaveConfirmation() {
        MessageResult result;
        result = MessageBoxService.ShowMessage(
            messageBoxText: &quot;Save Changes?&quot;,
            caption: &quot;DXApplication&quot;,
            icon: MessageIcon.Question,
            button: MessageButton.YesNoCancel,
            defaultResult: MessageResult.Cancel
        );
        switch (result) {
            case MessageResult.Yes:
                ButtonText = &quot;Changes Saved&quot;;
                break;
            case MessageResult.No:
                ButtonText = &quot;Changes Discarded&quot;;
                break;
            case MessageResult.Cancel:
                ButtonText = &quot;Continue Editing&quot;;
                break;
        }
    }
}
</code></pre></section>
<section id="tabpanel_jqfOlQXRPB-1_tabid-vb" role="tabpanel" data-tab="tabid-vb" aria-hidden="true" hidden="hidden">
<pre><code class="lang-vb">Public Class ViewModel
    Inherits ViewModelBase

    Public Overridable Property ButtonText As String = &quot;Save Changes Button&quot;

    Private ReadOnly Property MessageBoxService As IMessageBoxService
        Get
            Return GetService(Of IMessageBoxService)()
        End Get
    End Property

    &lt;Command&gt;
    Public Sub SaveConfirmation()
        Dim result As MessageResult
        result = MessageBoxService.ShowMessage(messageBoxText:=&quot;Save Changes?&quot;, caption:=&quot;DXApplication&quot;, icon:=MessageIcon.Question, button:=MessageButton.YesNoCancel, defaultResult:=MessageResult.Cancel)

        Select Case result
            Case MessageResult.Yes
                ButtonText = &quot;Changes Saved&quot;
            Case MessageResult.No
                ButtonText = &quot;Changes Discarded&quot;
            Case MessageResult.Cancel
                ButtonText = &quot;Continue Editing&quot;
        End Select
    End Sub
End Class
</code></pre></section>

Below is the list of examples that describes how to use the `DXMessageBoxService` in different View Models:

- Example: How to use MessageBoxService in ViewModels derived from the ViewModelBase class
- Example: How to use MessageBoxService in POCO View Models
- Example: How to use MessageBoxService in a custom View Model

## How to use MessageBoxService in ViewModels derived from the ViewModelBase class

This example demonstrates how to use the **DXMessageBoxService** in View Models derived from the [ViewModelBase](/WPF/17351/mvvm-framework/viewmodels/viewmodelbase) class. The View Models are related to each other by the parent-child relationship with the **ISupportParentViewModel** interface.

Refer to the [ViewModel relationships (ISupportParentViewModel)](/WPF/17449/mvvm-framework/viewmodels/viewmodel-relationships-isupportparentviewmodel) topic for more information on View Model parent-child relationships.

- ChildViewModel.cs
- MainView.xaml
- ChildView.xaml
- MainViewModel.cs
- ChildViewModel.vb
- MainViewModel.vb

<section id="tabpanel_Tpe9dRTCMp_tabid-csharpChildViewModel-cs" role="tabpanel" data-tab="tabid-csharpChildViewModel-cs">
<pre><code data-code-links="{&quot;/ (DevExpress.Mvvm)(?:;|$)/&quot;:&quot;/CoreLibraries/DevExpress.Mvvm&quot;,&quot;/ (System.Windows.Input)(?:;|$)/&quot;:&quot;https://learn.microsoft.com/dotnet/api/system.windows.input&quot;}" class="lang-csharp">using DevExpress.Mvvm;
using System.Windows.Input;

namespace Example.ViewModel {
    public class ChildViewModel : ViewModelBase {
        public ICommand ShowMessageCommand { get; private set; }
        public ChildViewModel() {
            ShowMessageCommand = new DelegateCommand(ShowMessage);
        }

        IMessageBoxService MessageBoxService { get { return GetService&lt;IMessageBoxService&gt;(ServiceSearchMode.PreferParents); } }
        void ShowMessage() {
            MessageBoxService.Show(&quot;This is ChildView&quot;);
        }
    }
}
</code></pre></section>
<section id="tabpanel_Tpe9dRTCMp_tabid-xamlMainView-xaml" role="tabpanel" data-tab="tabid-xamlMainView-xaml" aria-hidden="true" hidden="hidden">
<pre><code class="lang-xaml">&lt;UserControl x:Class=&quot;Example.View.MainView&quot;
    xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
    xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
    xmlns:ViewModel=&quot;clr-namespace:Example.ViewModel&quot;
    xmlns:View=&quot;clr-namespace:Example.View&quot;
    xmlns:dxmvvm=&quot;http://schemas.devexpress.com/winfx/2008/xaml/mvvm&quot;
    xmlns:dx=&quot;http://schemas.devexpress.com/winfx/2008/xaml/core&quot;
    xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
    xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
    mc:Ignorable=&quot;d&quot; d:DesignHeight=&quot;500&quot; d:DesignWidth=&quot;600&quot;&gt;
    &lt;UserControl.DataContext&gt;
        &lt;ViewModel:MainViewModel/&gt;
    &lt;/UserControl.DataContext&gt;
    &lt;dxmvvm:Interaction.Behaviors&gt;
        &lt;dx:DXMessageBoxService/&gt;
    &lt;/dxmvvm:Interaction.Behaviors&gt;

    &lt;Grid x:Name=&quot;LayoutRoot&quot; Background=&quot;White&quot;&gt;
        &lt;StackPanel Orientation=&quot;Vertical&quot;&gt;
            &lt;StackPanel Orientation=&quot;Horizontal&quot;&gt;
                &lt;TextBlock Text=&quot;MainView: &quot;/&gt;
                &lt;Button Content=&quot;Show Message&quot; Command=&quot;{Binding ShowMessageCommand}&quot;/&gt;
            &lt;/StackPanel&gt;
            &lt;StackPanel Orientation=&quot;Horizontal&quot;&gt;
                &lt;TextBlock Text=&quot;ChildView: &quot; /&gt;
                &lt;View:ChildView dxmvvm:ViewModelExtensions.ParentViewModel=&quot;{Binding DataContext, ElementName=LayoutRoot}&quot;/&gt;
            &lt;/StackPanel&gt;
        &lt;/StackPanel&gt;
    &lt;/Grid&gt;
&lt;/UserControl&gt;
</code></pre></section>
<section id="tabpanel_Tpe9dRTCMp_tabid-xamlChildView-xaml" role="tabpanel" data-tab="tabid-xamlChildView-xaml" aria-hidden="true" hidden="hidden">
<pre><code class="lang-xaml">&lt;UserControl x:Class=&quot;Example.View.ChildView&quot;
             xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
             xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
             xmlns:ViewModel=&quot;clr-namespace:Example.ViewModel&quot;
             xmlns:dxmvvm=&quot;http://schemas.devexpress.com/winfx/2008/xaml/mvvm&quot;
             xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot; 
             xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot; 
             mc:Ignorable=&quot;d&quot; 
             d:DesignHeight=&quot;300&quot; d:DesignWidth=&quot;300&quot;&gt;
    &lt;UserControl.DataContext&gt;
        &lt;ViewModel:ChildViewModel/&gt;
    &lt;/UserControl.DataContext&gt;
    &lt;Grid&gt;
        &lt;Button Content=&quot;ChildView: Show Message&quot; Command=&quot;{Binding ShowMessageCommand}&quot;/&gt;
    &lt;/Grid&gt;
&lt;/UserControl&gt;
</code></pre></section>
<section id="tabpanel_Tpe9dRTCMp_tabid-csharpMainViewModel-cs" role="tabpanel" data-tab="tabid-csharpMainViewModel-cs" aria-hidden="true" hidden="hidden">
<pre><code data-code-links="{&quot;/ (DevExpress.Mvvm)(?:;|$)/&quot;:&quot;/CoreLibraries/DevExpress.Mvvm&quot;,&quot;/ (System.Windows.Input)(?:;|$)/&quot;:&quot;https://learn.microsoft.com/dotnet/api/system.windows.input&quot;}" class="lang-csharp">using DevExpress.Mvvm;
using System.Windows.Input;

namespace Example.ViewModel {
    public class MainViewModel : ViewModelBase {
        public ICommand ShowMessageCommand { get; private set; }
        IMessageBoxService MessageBoxService { get { return GetService&lt;IMessageBoxService&gt;(); } }

        public MainViewModel() {
            ShowMessageCommand = new DelegateCommand(ShowMessage);
        }
        void ShowMessage() {
            MessageBoxService.Show(&quot;This is MainView!&quot;);
        }
    }
}
</code></pre></section>
<section id="tabpanel_Tpe9dRTCMp_tabid-vbChildViewModel-vb" role="tabpanel" data-tab="tabid-vbChildViewModel-vb" aria-hidden="true" hidden="hidden">
<pre><code data-code-links="{&quot;/ (DevExpress.Mvvm)(?:;|$)/&quot;:&quot;/CoreLibraries/DevExpress.Mvvm&quot;,&quot;/ (System.Windows.Input)(?:;|$)/&quot;:&quot;https://learn.microsoft.com/dotnet/api/system.windows.input&quot;}" class="lang-vb">Imports DevExpress.Mvvm
Imports System.Windows.Input

Namespace Example.ViewModel
    Public Class ChildViewModel
        Inherits ViewModelBase

        Private privateShowMessageCommand As ICommand
        Public Property ShowMessageCommand() As ICommand
            Get
                Return privateShowMessageCommand
            End Get
            Private Set(ByVal value As ICommand)
                privateShowMessageCommand = value
            End Set
        End Property
        Public Sub New()
            ShowMessageCommand = New DelegateCommand(AddressOf ShowMessage)
        End Sub

        Private ReadOnly Property MessageBoxService() As IMessageBoxService
            Get
                Return GetService(Of IMessageBoxService)(ServiceSearchMode.PreferParents)
            End Get
        End Property
        Private Sub ShowMessage()
            MessageBoxService.Show(&quot;This is ChildView&quot;)
        End Sub
    End Class
End Namespace
</code></pre></section>
<section id="tabpanel_Tpe9dRTCMp_tabid-vbMainViewModel-vb" role="tabpanel" data-tab="tabid-vbMainViewModel-vb" aria-hidden="true" hidden="hidden">
<pre><code data-code-links="{&quot;/ (DevExpress.Mvvm)(?:;|$)/&quot;:&quot;/CoreLibraries/DevExpress.Mvvm&quot;,&quot;/ (System.Windows.Input)(?:;|$)/&quot;:&quot;https://learn.microsoft.com/dotnet/api/system.windows.input&quot;}" class="lang-vb">Imports DevExpress.Mvvm
Imports System.Windows.Input

Namespace Example.ViewModel
    Public Class MainViewModel
        Inherits ViewModelBase

        Private privateShowMessageCommand As ICommand
        Public Property ShowMessageCommand() As ICommand
            Get
                Return privateShowMessageCommand
            End Get
            Private Set(ByVal value As ICommand)
                privateShowMessageCommand = value
            End Set
        End Property
        Private ReadOnly Property MessageBoxService() As IMessageBoxService
            Get
                Return GetService(Of IMessageBoxService)()
            End Get
        End Property

        Public Sub New()
            ShowMessageCommand = New DelegateCommand(AddressOf ShowMessage)
        End Sub
        Private Sub ShowMessage()
            MessageBoxService.Show(&quot;This is MainView!&quot;)
        End Sub
    End Class
End Namespace
</code></pre></section>

## How to use MessageBoxService in POCO View Models

This example demonstrates how to use the **DXMessageBoxService** in [POCO](/WPF/17352/mvvm-framework/viewmodels/runtime-generated-poco-viewmodels) View Models. The View Models are related to each other by the parent-child relationship with the **ISupportParentViewModel** interface.

Refer to the [ViewModel relationships (ISupportParentViewModel)](/WPF/17449/mvvm-framework/viewmodels/viewmodel-relationships-isupportparentviewmodel) topic for more information on View Model parent-child relationships.

- ChildView.xaml
- MainView.xaml
- ChildViewModel.cs
- MainViewModel.cs
- MainViewModel.vb
- ChildViewModel.vb

<section id="tabpanel_29PLIgvd8T_tabid-xamlChildView-xaml" role="tabpanel" data-tab="tabid-xamlChildView-xaml" aria-hidden="true" hidden="hidden">
<pre><code class="lang-xaml">&lt;UserControl x:Class=&quot;Example.View.ChildView&quot;
             xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
             xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
             xmlns:ViewModel=&quot;clr-namespace:Example.ViewModel&quot;
             xmlns:dxmvvm=&quot;http://schemas.devexpress.com/winfx/2008/xaml/mvvm&quot;
             xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot; 
             xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot; 
             mc:Ignorable=&quot;d&quot; 
             d:DesignHeight=&quot;300&quot; d:DesignWidth=&quot;300&quot;
             DataContext=&quot;{dxmvvm:ViewModelSource ViewModel:ChildViewModel}&quot;&gt;
    &lt;Grid&gt;
        &lt;Button Content=&quot;ChildView: Show Message&quot; Command=&quot;{Binding ShowMessageCommand}&quot;/&gt;
    &lt;/Grid&gt;
&lt;/UserControl&gt;
</code></pre></section>
<section id="tabpanel_29PLIgvd8T_tabid-xamlMainView-xaml" role="tabpanel" data-tab="tabid-xamlMainView-xaml" aria-hidden="true" hidden="hidden">
<pre><code class="lang-xaml">&lt;UserControl x:Class=&quot;Example.View.MainView&quot;
    xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
    xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
    xmlns:ViewModel=&quot;clr-namespace:Example.ViewModel&quot;
    xmlns:View=&quot;clr-namespace:Example.View&quot;
    xmlns:dxmvvm=&quot;http://schemas.devexpress.com/winfx/2008/xaml/mvvm&quot;
    xmlns:dx=&quot;http://schemas.devexpress.com/winfx/2008/xaml/core&quot;
    xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
    xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
    mc:Ignorable=&quot;d&quot; d:DesignHeight=&quot;500&quot; d:DesignWidth=&quot;600&quot;
    DataContext=&quot;{dxmvvm:ViewModelSource ViewModel:MainViewModel}&quot;&gt;
    &lt;dxmvvm:Interaction.Behaviors&gt;
        &lt;dx:DXMessageBoxService/&gt;
    &lt;/dxmvvm:Interaction.Behaviors&gt;

    &lt;Grid x:Name=&quot;LayoutRoot&quot; Background=&quot;White&quot;&gt;
        &lt;StackPanel Orientation=&quot;Vertical&quot;&gt;
            &lt;StackPanel Orientation=&quot;Horizontal&quot;&gt;
                &lt;TextBlock Text=&quot;MainView: &quot;/&gt;
                &lt;Button Content=&quot;Show Message&quot; Command=&quot;{Binding ShowMessageCommand}&quot;/&gt;
            &lt;/StackPanel&gt;
            &lt;StackPanel Orientation=&quot;Horizontal&quot;&gt;
                &lt;TextBlock Text=&quot;ChildView: &quot; /&gt;
                &lt;View:ChildView dxmvvm:ViewModelExtensions.ParentViewModel=&quot;{Binding DataContext, ElementName=LayoutRoot}&quot;/&gt;
            &lt;/StackPanel&gt;
        &lt;/StackPanel&gt;
    &lt;/Grid&gt;
&lt;/UserControl&gt;
</code></pre></section>
<section id="tabpanel_29PLIgvd8T_tabid-csharpChildViewModel-cs" role="tabpanel" data-tab="tabid-csharpChildViewModel-cs">
<pre><code data-code-links="{&quot;/ (DevExpress.Mvvm)(?:;|$)/&quot;:&quot;/CoreLibraries/DevExpress.Mvvm&quot;,&quot;/ (DevExpress.Mvvm.DataAnnotations)(?:;|$)/&quot;:&quot;/CoreLibraries/DevExpress.Mvvm.DataAnnotations&quot;}" class="lang-csharp">using DevExpress.Mvvm;
using DevExpress.Mvvm.DataAnnotations;

namespace Example.ViewModel {
    public class ChildViewModel {
        [ServiceProperty(SearchMode=ServiceSearchMode.PreferParents)]
        protected virtual IMessageBoxService MessageBoxService { get { return null; } }
        public void ShowMessage() {
            MessageBoxService.Show(&quot;This is ChildView&quot;);
        }
    }
}
</code></pre></section>
<section id="tabpanel_29PLIgvd8T_tabid-csharpMainViewModel-cs" role="tabpanel" data-tab="tabid-csharpMainViewModel-cs" aria-hidden="true" hidden="hidden">
<pre><code data-code-links="{&quot;/ (DevExpress.Mvvm)(?:;|$)/&quot;:&quot;/CoreLibraries/DevExpress.Mvvm&quot;,&quot;/ (System.Windows.Input)(?:;|$)/&quot;:&quot;https://learn.microsoft.com/dotnet/api/system.windows.input&quot;}" class="lang-csharp">using DevExpress.Mvvm;
using System.Windows.Input;

namespace Example.ViewModel {
    public class MainViewModel {
        protected virtual IMessageBoxService MessageBoxService { get { return null; } }
        public void ShowMessage() {
            MessageBoxService.Show(&quot;This is MainView!&quot;);
        }
    }
}
</code></pre></section>
<section id="tabpanel_29PLIgvd8T_tabid-vbMainViewModel-vb" role="tabpanel" data-tab="tabid-vbMainViewModel-vb" aria-hidden="true" hidden="hidden">
<pre><code data-code-links="{&quot;/ (DevExpress.Mvvm)(?:;|$)/&quot;:&quot;/CoreLibraries/DevExpress.Mvvm&quot;,&quot;/ (System.Windows.Input)(?:;|$)/&quot;:&quot;https://learn.microsoft.com/dotnet/api/system.windows.input&quot;}" class="lang-vb">Imports DevExpress.Mvvm
Imports System.Windows.Input

Namespace Example.ViewModel
    Public Class MainViewModel
        Protected Overridable ReadOnly Property MessageBoxService() As IMessageBoxService
            Get
                Return Nothing
            End Get
        End Property
        Public Sub ShowMessage()
            MessageBoxService.Show(&quot;This is MainView!&quot;)
        End Sub
    End Class
End Namespace
</code></pre></section>
<section id="tabpanel_29PLIgvd8T_tabid-vbChildViewModel-vb" role="tabpanel" data-tab="tabid-vbChildViewModel-vb" aria-hidden="true" hidden="hidden">
<pre><code data-code-links="{&quot;/ (DevExpress.Mvvm)(?:;|$)/&quot;:&quot;/CoreLibraries/DevExpress.Mvvm&quot;,&quot;/ (DevExpress.Mvvm.DataAnnotations)(?:;|$)/&quot;:&quot;/CoreLibraries/DevExpress.Mvvm.DataAnnotations&quot;}" class="lang-vb">Imports DevExpress.Mvvm
Imports DevExpress.Mvvm.DataAnnotations

Namespace Example.ViewModel
    Public Class ChildViewModel
        &lt;ServiceProperty(SearchMode:=ServiceSearchMode.PreferParents)&gt; _
        Protected Overridable ReadOnly Property MessageBoxService() As IMessageBoxService
            Get
                Return Nothing
            End Get
        End Property
        Public Sub ShowMessage()
            MessageBoxService.Show(&quot;This is ChildView&quot;)
        End Sub
    End Class
End Namespace
</code></pre></section>

## How to use MessageBoxService in a custom View Model

This example demonstrates how to use the **DXMessageBoxService** in a custom View Model (not derived from the [ViewModelBase](/WPF/17351/mvvm-framework/viewmodels/viewmodelbase) class and not a [POCO](/WPF/17352/mvvm-framework/viewmodels/runtime-generated-poco-viewmodels) View Model).

Refer to the [Services in custom ViewModels](/WPF/17450/mvvm-framework/services/services-in-custom-viewmodels) topic for more information on how to use the Service mechanism in a custom View Model.

Custom View Models in this example are related to each other with the parent-child relationship. This is achieved by supporting the **ISupportParentViewModel** interface in the View Models.

Refer to the [ViewModel relationships (ISupportParentViewModel)](/WPF/17449/mvvm-framework/viewmodels/viewmodel-relationships-isupportparentviewmodel) topic for more information on View Model parent-child relationships.

- ChildViewModel.vb
- MainViewModel.vb
- ChildView.xaml
- MainView.xaml
- MainViewModel.cs
- ChildViewModel.cs

<section id="tabpanel_CXdfC5Yoq2_tabid-vbChildViewModel-vb" role="tabpanel" data-tab="tabid-vbChildViewModel-vb" aria-hidden="true" hidden="hidden">
<pre><code data-code-links="{&quot;/ (DevExpress.Mvvm)(?:;|$)/&quot;:&quot;/CoreLibraries/DevExpress.Mvvm&quot;,&quot;/ (System.Windows.Input)(?:;|$)/&quot;:&quot;https://learn.microsoft.com/dotnet/api/system.windows.input&quot;}" class="lang-vb">Imports DevExpress.Mvvm
Imports System.Windows.Input

Namespace Example.ViewModel
    Public Class ChildViewModel
        Implements ISupportServices, ISupportParentViewModel

        Private serviceContainer_Renamed As IServiceContainer = Nothing
        Protected ReadOnly Property ServiceContainer() As IServiceContainer
            Get
                If serviceContainer_Renamed Is Nothing Then
                    serviceContainer_Renamed = New ServiceContainer(Me)
                End If
                Return serviceContainer_Renamed
            End Get
        End Property
        Private ReadOnly Property ISupportServices_ServiceContainer() As IServiceContainer Implements ISupportServices.ServiceContainer
            Get
                Return ServiceContainer
            End Get
        End Property
        Private Property ISupportParentViewModel_ParentViewModel() As Object Implements ISupportParentViewModel.ParentViewModel

        Private ReadOnly Property MessageBoxService() As IMessageBoxService
            Get
                Return ServiceContainer.GetService(Of IMessageBoxService)(ServiceSearchMode.PreferParents)
            End Get
        End Property

        Private privateShowMessageCommand As ICommand
        Public Property ShowMessageCommand() As ICommand
            Get
                Return privateShowMessageCommand
            End Get
            Private Set(ByVal value As ICommand)
                privateShowMessageCommand = value
            End Set
        End Property
        Public Sub New()
            ShowMessageCommand = New DelegateCommand(AddressOf ShowMessage)
        End Sub
        Private Sub ShowMessage()
            MessageBoxService.Show(&quot;This is ChildView&quot;)
        End Sub
    End Class
End Namespace
</code></pre></section>
<section id="tabpanel_CXdfC5Yoq2_tabid-vbMainViewModel-vb" role="tabpanel" data-tab="tabid-vbMainViewModel-vb" aria-hidden="true" hidden="hidden">
<pre><code data-code-links="{&quot;/ (DevExpress.Mvvm)(?:;|$)/&quot;:&quot;/CoreLibraries/DevExpress.Mvvm&quot;,&quot;/ (System.Windows.Input)(?:;|$)/&quot;:&quot;https://learn.microsoft.com/dotnet/api/system.windows.input&quot;}" class="lang-vb">Imports DevExpress.Mvvm
Imports System.Windows.Input

Namespace Example.ViewModel
    Public Class MainViewModel
        Implements ISupportServices

        Private serviceContainer_Renamed As IServiceContainer = Nothing
        Protected ReadOnly Property ServiceContainer() As IServiceContainer
            Get
                If serviceContainer_Renamed Is Nothing Then
                    serviceContainer_Renamed = New ServiceContainer(Me)
                End If
                Return serviceContainer_Renamed
            End Get
        End Property
        Private ReadOnly Property ISupportServices_ServiceContainer() As IServiceContainer Implements ISupportServices.ServiceContainer
            Get
                Return ServiceContainer
            End Get
        End Property
        Private ReadOnly Property MessageBoxService() As IMessageBoxService
            Get
                Return ServiceContainer.GetService(Of IMessageBoxService)()
            End Get
        End Property

        Private privateShowMessageCommand As ICommand
        Public Property ShowMessageCommand() As ICommand
            Get
                Return privateShowMessageCommand
            End Get
            Private Set(ByVal value As ICommand)
                privateShowMessageCommand = value
            End Set
        End Property
        Public Sub New()
            ShowMessageCommand = New DelegateCommand(AddressOf ShowMessage)
        End Sub
        Private Sub ShowMessage()
            MessageBoxService.Show(&quot;This is MainView!&quot;)
        End Sub
    End Class
End Namespace
</code></pre></section>
<section id="tabpanel_CXdfC5Yoq2_tabid-xamlChildView-xaml" role="tabpanel" data-tab="tabid-xamlChildView-xaml" aria-hidden="true" hidden="hidden">
<pre><code class="lang-xaml">&lt;UserControl x:Class=&quot;Example.View.ChildView&quot;
             xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
             xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
             xmlns:ViewModel=&quot;clr-namespace:Example.ViewModel&quot;
             xmlns:dxmvvm=&quot;http://schemas.devexpress.com/winfx/2008/xaml/mvvm&quot;
             xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot; 
             xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot; 
             mc:Ignorable=&quot;d&quot; 
             d:DesignHeight=&quot;300&quot; d:DesignWidth=&quot;300&quot;&gt;
    &lt;UserControl.DataContext&gt;
        &lt;ViewModel:ChildViewModel/&gt;
    &lt;/UserControl.DataContext&gt;
    &lt;Grid&gt;
        &lt;Button Content=&quot;ChildView: Show Message&quot; Command=&quot;{Binding ShowMessageCommand}&quot;/&gt;
    &lt;/Grid&gt;
&lt;/UserControl&gt;
</code></pre></section>
<section id="tabpanel_CXdfC5Yoq2_tabid-xamlMainView-xaml" role="tabpanel" data-tab="tabid-xamlMainView-xaml" aria-hidden="true" hidden="hidden">
<pre><code class="lang-xaml">&lt;UserControl x:Class=&quot;Example.View.MainView&quot;
    xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
    xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
    xmlns:ViewModel=&quot;clr-namespace:Example.ViewModel&quot;
    xmlns:View=&quot;clr-namespace:Example.View&quot;
    xmlns:dxmvvm=&quot;http://schemas.devexpress.com/winfx/2008/xaml/mvvm&quot;
    xmlns:dx=&quot;http://schemas.devexpress.com/winfx/2008/xaml/core&quot;
    xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
    xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
    mc:Ignorable=&quot;d&quot; d:DesignHeight=&quot;500&quot; d:DesignWidth=&quot;600&quot;&gt;
    &lt;UserControl.DataContext&gt;
        &lt;ViewModel:MainViewModel/&gt;
    &lt;/UserControl.DataContext&gt;
    &lt;dxmvvm:Interaction.Behaviors&gt;
        &lt;dx:DXMessageBoxService/&gt;
    &lt;/dxmvvm:Interaction.Behaviors&gt;

    &lt;Grid x:Name=&quot;LayoutRoot&quot; Background=&quot;White&quot;&gt;
        &lt;StackPanel Orientation=&quot;Vertical&quot;&gt;
            &lt;StackPanel Orientation=&quot;Horizontal&quot;&gt;
                &lt;TextBlock Text=&quot;MainView: &quot;/&gt;
                &lt;Button Content=&quot;Show Message&quot; Command=&quot;{Binding ShowMessageCommand}&quot;/&gt;
            &lt;/StackPanel&gt;
            &lt;StackPanel Orientation=&quot;Horizontal&quot;&gt;
                &lt;TextBlock Text=&quot;ChildView: &quot; /&gt;
                &lt;View:ChildView dxmvvm:ViewModelExtensions.ParentViewModel=&quot;{Binding DataContext, ElementName=LayoutRoot}&quot;/&gt;
            &lt;/StackPanel&gt;
        &lt;/StackPanel&gt;
    &lt;/Grid&gt;
&lt;/UserControl&gt;
</code></pre></section>
<section id="tabpanel_CXdfC5Yoq2_tabid-csharpMainViewModel-cs" role="tabpanel" data-tab="tabid-csharpMainViewModel-cs" aria-hidden="true" hidden="hidden">
<pre><code data-code-links="{&quot;/ (DevExpress.Mvvm)(?:;|$)/&quot;:&quot;/CoreLibraries/DevExpress.Mvvm&quot;,&quot;/ (System.Windows.Input)(?:;|$)/&quot;:&quot;https://learn.microsoft.com/dotnet/api/system.windows.input&quot;}" class="lang-csharp">using DevExpress.Mvvm;
using System.Windows.Input;

namespace Example.ViewModel {
    public class MainViewModel : ISupportServices {
        IServiceContainer serviceContainer = null;
        protected IServiceContainer ServiceContainer {
            get {
                if(serviceContainer == null)
                    serviceContainer = new ServiceContainer(this);
                return serviceContainer; 
            }
        }
        IServiceContainer ISupportServices.ServiceContainer { get { return ServiceContainer; } }
        IMessageBoxService MessageBoxService { get { return ServiceContainer.GetService&lt;IMessageBoxService&gt;(); } }

        public ICommand ShowMessageCommand { get; private set; }
        public MainViewModel() {
            ShowMessageCommand = new DelegateCommand(ShowMessage);
        }
        void ShowMessage() {
            MessageBoxService.Show(&quot;This is MainView!&quot;);
        }
    }
}
</code></pre></section>
<section id="tabpanel_CXdfC5Yoq2_tabid-csharpChildViewModel-cs" role="tabpanel" data-tab="tabid-csharpChildViewModel-cs">
<pre><code data-code-links="{&quot;/ (DevExpress.Mvvm)(?:;|$)/&quot;:&quot;/CoreLibraries/DevExpress.Mvvm&quot;,&quot;/ (System.Windows.Input)(?:;|$)/&quot;:&quot;https://learn.microsoft.com/dotnet/api/system.windows.input&quot;}" class="lang-csharp">using DevExpress.Mvvm;
using System.Windows.Input;

namespace Example.ViewModel {
    public class ChildViewModel : ISupportServices, ISupportParentViewModel {
        IServiceContainer serviceContainer = null;
        protected IServiceContainer ServiceContainer {
            get {
                if(serviceContainer == null)
                    serviceContainer = new ServiceContainer(this);
                return serviceContainer;
            }
        }
        IServiceContainer ISupportServices.ServiceContainer { get { return ServiceContainer; } }
        object ISupportParentViewModel.ParentViewModel { get; set; }

        IMessageBoxService MessageBoxService { get { return ServiceContainer.GetService&lt;IMessageBoxService&gt;(ServiceSearchMode.PreferParents); } }

        public ICommand ShowMessageCommand { get; private set; }
        public ChildViewModel() {
            ShowMessageCommand = new DelegateCommand(ShowMessage);
        }
        void ShowMessage() {
            MessageBoxService.Show(&quot;This is ChildView&quot;);
        }
    }
}
</code></pre></section>