Skip to main content
A newer version of this page is available. .

DXMessageBoxService

  • 7 minutes to read

The DXMessageBoxService is a IMessageBoxService implementation that uses the ThemedMessageBox control to show messages.

DXMessageBox Collage

Note

Use the UseThemedWindowInServices compatibility property to use the DXMessageBox control in the DXMessageBoxService.

This topic contains examples that describes how to use the DXMessageBoxService.

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 class. The View Models are related to each other by the parent-child relationship with the ISupportParentViewModel interface.

Refer to the ViewModel relationships (ISupportParentViewModel) topic for more information on View Model parent-child relationships.

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<IMessageBoxService>(ServiceSearchMode.PreferParents); } }
        void ShowMessage() {
            MessageBoxService.Show("This is ChildView");
        }
    }
}

How to use MessageBoxService in POCO View Models

This example demonstrates how to use the DXMessageBoxService in POCO 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) topic for more information on View Model parent-child relationships.

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("This is ChildView");
        }
    }
}

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 class and not a POCO View Model).

Refer to the 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) topic for more information on View Model parent-child relationships.

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<IMessageBoxService>(ServiceSearchMode.PreferParents); } }

        public ICommand ShowMessageCommand { get; private set; }
        public ChildViewModel() {
            ShowMessageCommand = new DelegateCommand(ShowMessage);
        }
        void ShowMessage() {
            MessageBoxService.Show("This is ChildView");
        }
    }
}