Skip to content

Message box

Mattias Kindborg edited this page May 19, 2016 · 2 revisions

To show a message box start by registering the view by decorating the XAML with the attached property DialogServiceViews.IsRegistered.

<UserControl
    x:Class="DemoApplication.Features.MessageBox.Views.MessageBoxTabContent"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:md="https://github.com/fantasticfiasco/mvvm-dialogs"
    md:DialogServiceViews.IsRegistered="True">

</UserControl>

In the view model, open the dialog by calling IDialogService.ShowMessageBox.

public class MessageBoxTabContentViewModel : INotifyPropertyChanged
{
    private readonly IDialogService dialogService;
  
    public MessageBoxTabContentViewModel(IDialogService dialogService)
    {
        this.dialogService = dialogService;
    }
  
    private void ShowMessageBox()
    {
        dialogService.ShowMessageBox(
            this,
            "This is the text.",
            "This Is The Caption",
            MessageBoxButton.OKCancel,
            MessageBoxImage.Information);
    }
}