WPFMessageBoxService ClassDW.WPFToolkit Documentation
Wraps up the static MessageBox object to have it testable. See MessageBox.
Inheritance Hierarchy

SystemObject
  DW.WPFToolkit.ServicesWPFMessageBoxService

Namespace: DW.WPFToolkit.Services
Assembly: DW.WPFToolkit (in DW.WPFToolkit.dll) Version: 5.6.0.0
Syntax

C#
public class WPFMessageBoxService : IWPFMessageBoxService

The WPFMessageBoxService type exposes the following members.

Constructors

  NameDescription
Public methodWPFMessageBoxService
Initializes a new instance of the DW.WPFToolkit.Services.WPFMessageBoxService class.
Top
Methods

  NameDescription
Public methodRegisterOwner
Registers an owner window by a key to be used in the show methods.
Public methodShow(String)
Displays a message box that has a message and that returns a result.
Public methodShow(Object, String)
Displays a message box in front of the specified window. The message box displays a message and returns a result.
Public methodShow(String, String)
Displays a message box that has a message and title bar caption; and that returns a result.
Public methodShow(Object, String, String)
Displays a message box in front of the specified window. The message box displays a message and title bar caption; and it returns a result.
Public methodShow(String, String, WPFMessageBoxButtons)
Displays a message box that has a message, title bar caption, and button; and that returns a result.
Public methodShow(Object, String, String, WPFMessageBoxButtons)
Displays a message box in front of the specified window. The message box displays a message, title bar caption, and button; and it also returns a result.
Public methodShow(String, String, WPFMessageBoxButtons, WPFMessageBoxImage)
Displays a message box that has a message, title bar caption, button, and icon; and that returns a result.
Public methodShow(Object, String, String, WPFMessageBoxButtons, WPFMessageBoxImage)
Displays a message box in front of the specified window. The message box displays a message, title bar caption, button, and icon; and it also returns a result.
Public methodShow(String, String, WPFMessageBoxButtons, WPFMessageBoxImage, WPFMessageBoxResult)
Displays a message box that has a message, title bar caption, button, and icon; and that accepts a default message box result and returns a result.
Public methodShow(Object, String, String, WPFMessageBoxButtons, WPFMessageBoxImage, WPFMessageBoxResult)
Displays a message box in front of the specified window. The message box displays a message, title bar caption, button, and icon; and accepts a default message box result and returns a result.
Public methodShow(String, String, WPFMessageBoxButtons, WPFMessageBoxImage, WPFMessageBoxResult, WPFMessageBoxOptions)
Displays a message box that has a message, title bar caption, button, and icon; and that accepts a default message box result, complies with the specified options, and returns a result.
Public methodShow(Object, String, String, WPFMessageBoxButtons, WPFMessageBoxImage, WPFMessageBoxResult, WPFMessageBoxOptions)
Displays a message box in front of the specified window. The message box displays a message, title bar caption, button, and icon; and accepts a default message box result, complies with the specified options, and returns a result.
Public methodUnregisterOwner
Removes a registered owner window by its key.
Top
Examples

C#
private readonly IMessageBoxService _messageBoxService;

public MainViewModel(IMessageBoxService messageBoxService)
{
    _messageBoxService = messageBoxService;
}

public void Show1()
{
    _messageBoxService.Show("Show the messagebox without an owner");
}

public void Show2()
{
    _messageBoxService.Show("Show the messagebox without an owner", "But with a caption");
}

public void Show3()
{
    _messageBoxService.Show(ViewKey.MainView, "Show the messagebox with an owner", "And with a caption", MessageBoxButton.OK, MessageBoxImage.Information);
}
C#
public partial class App
{
    private readonly IWindowService _windowService;
    private readonly IMessageBoxService _messageBoxService;

    public App()
    {
        _windowService = new WindowService();
        _messageBoxService = new MessageBoxService();

        RegisterServices();
    }

    private void RegisterServices()
    {
        _windowService.Register<MainView>(ViewKey.MainView);
        _windowService.WindowCreated += HandleWindowCreated;
        _windowService.WindowClosed += HandleWindowClosed;
    }

    private void HandleWindowCreated(object sender, WindowStateEventArgs e)
    {
        _messageBoxService.RegisterOwner(e.Window, e.WindowKey);
    }

    private void HandleWindowClosed(object sender, WindowStateEventArgs e)
    {
        _messageBoxService.UnregisterOwner(e.WindowKey);
    }

    protected override void OnStartup(StartupEventArgs e)
    {
        _windowService.ShowDialog(ViewKey.MainView, new MainViewModel());
    }
}

public enum ViewKey
{
    MainView
}
See Also

Reference