Back to Devexpress

DXMessageBoxService Class

wpf-devexpress-dot-xpf-dot-core-4412e451.md

latest7.1 KB
Original Source

DXMessageBoxService Class

Allows you to display message boxes.

Namespace : DevExpress.Xpf.Core

Assembly : DevExpress.Xpf.Core.v25.2.dll

NuGet Package : DevExpress.Wpf.Core

Declaration

csharp
[TargetType(typeof(Window))]
[TargetType(typeof(UserControl))]
public class DXMessageBoxService :
    ServiceBase,
    IMessageBoxService
vb
<TargetType(GetType(UserControl))>
<TargetType(GetType(Window))>
Public Class DXMessageBoxService
    Inherits ServiceBase
    Implements IMessageBoxService

Remarks

Note

DXMessageBoxService uses the ThemedMessageBox instead of DXMessageBox. Use the UseThemedWindowInServices compatibility property to use the DXMessageBox in this service.

See Services for more information.

Example

The following code defines a command within a View Model that displays a message box via a dedicated Message Box service. The service is accessed via the IServiceContainer.GetService<T> method invoked on the View Model’s ServiceContainer protected property. The GetService method retrieves an actual service from a View that implements the specified IMessageBoxService interface. In our example, the method will retrieve a DXMessageBoxService object defined within the View.

Services from a View can be retrieved by a ViewModel if the following conditions are met:

  • An actual service object (in this case, the DXMessageBoxService object) is added within a View to the Interaction.Behaviors collection.

  • The View’s DataContext is set to your View Model.

  • C#

  • VB.NET

  • XAML

csharp
using System;
using System.Windows.Input;
using DevExpress.Xpf.Mvvm;

public class ViewModel1 : ViewModelBase {
    //...
    ICommand showAboutCommand;

    public ICommand ShowAboutCommand {
        get {
            if (showAboutCommand == null) {
                showAboutCommand = new DelegateCommand<object>(o => {
                    ServiceContainer.GetService<IMessageBoxService>().Show("About Window");
                });
            }
            return showAboutCommand;
        }
    }
}
vb
Imports System.Windows.Input
Imports DevExpress.Xpf.Mvvm

Public Class ViewModel1
    Inherits ViewModelBase
    '...
    Private m_showAboutCommand As ICommand

    Public ReadOnly Property ShowAboutCommand() As ICommand
        Get
            If m_showAboutCommand Is Nothing Then
                m_showAboutCommand = New DelegateCommand(Of Object)(
                    Sub(o)
                        ServiceContainer.GetService(Of IMessageBoxService)().Show("About Window")
                    End Sub)
            End If
            Return m_showAboutCommand
        End Get
    End Property
End Class
xaml
<dxcore:DXWindow x:Class="Application1.MainWindow"
    . . .
    xmlns:dxcore="http://schemas.devexpress.com/winfx/2008/xaml/core"
    xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm" 
    DataContext="{DynamicResource ViewModel}">

    <Window.Resources>
        <local:ViewModel1 x:Key="ViewModel"/>
    </Window.Resources>

    <dxmvvm:Interaction.Behaviors>
        <dx:DXMessageBoxService/>
        . . .
    </dxmvvm:Interaction.Behaviors>

</dxcore:DXWindow>

The following code snippets (auto-collected from DevExpress Examples) contain references to the DXMessageBoxService class.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

reporting-wpf-customize-keyboard-shortcuts-in-the-report-designer/CS/T461248/MainWindow.xaml#L14

xml
<mvvm:Interaction.Behaviors>
    <dx:DXMessageBoxService />
</mvvm:Interaction.Behaviors>

spell-checker-bind-dictionaries-in-mvvm-applications/CS/DXSpellCheckerBindingDictionaries/MainWindow.xaml#L16

xml
<dxmvvm:Interaction.Behaviors>
    <dx:DXMessageBoxService />
</dxmvvm:Interaction.Behaviors>

how-to-use-the-wpf-wizardservice/CS/VM-DrivenWizard/MainWindow.xaml#L49

xml
</dxco:WizardService>
<dx:DXMessageBoxService />
<dxmvvm:EventToCommand EventName="Loaded" Command="{Binding ViewLoadedCommand}" />

reporting-wpf-mvvm-show-report-document-preview/CS/MainWindow.xaml#L12

xml
<dxmvvm:Interaction.Behaviors>
    <dx:DXMessageBoxService />
    <dx:DialogService Name="previewDialogService">

wpf-diagram-mdi/CS/MainWindow.xaml#L60

xml
Title="Open Diagram" />
    <dx:DXMessageBoxService />
</dxmvvm:Interaction.Behaviors>

Inheritance

Show 11 items

Object DispatcherObject DependencyObject Freezable Animatable DevExpress.Mvvm.UI.Interactivity.AttachableObjectBase DevExpress.Mvvm.UI.Interactivity.Behavior DevExpress.Mvvm.UI.Interactivity.Behavior<FrameworkElement> DevExpress.Mvvm.UI.ServiceBaseGeneric<FrameworkElement> ServiceBase DXMessageBoxService

See Also

DXMessageBoxService Members

Services

DevExpress.Xpf.Core Namespace