MessageBoxService

  • 2 minutes to read

The MessageBoxService is a DevExpress.Mvvm.IMessageBoxService implementation that allows you to show messages.

The following example uses the MessageBoxService in a View Model derived from the ViewModelBase class.

<UserControl x:Class="WinUIApp.View" 
             xmlns:dxmvvmi="using:DevExpress.WinUI.Mvvm.UI.Interactivity"
             xmlns:dxmvvm="using:DevExpress.WinUI.Mvvm.UI"
             xmlns:ViewModel="using:WinUIApp.ViewModel" ...> 
    <UserControl.DataContext>
        <ViewModel:ViewModel/>
    </UserControl.DataContext>
    <dxmvvmi:Interaction.Behaviors>
        <dxmvvm:MessageBoxService/>
    </dxmvvmi:Interaction.Behaviors>
    ...
        <Button Content="Save" Command="{Binding SaveCommand}"/>
    ...
</UserControl>
public class ViewModel : ViewModelBase {
    public DelegateCommand SaveCommand { get; private set; }
    IMessageBoxService MessageBoxService { get { return GetService<IMessageBoxService>(); } }
    public ViewModel() {
        SaveCommand = new DelegateCommand(() => Save());
    }
    public async void Save() {
        MessageResult result = await MessageBoxService.ShowAsync(
            messageBoxText: "Are you sure you want to save?", 
            caption: "Confirmation", 
            button: MessageButton.OKCancel);
        if(result == MessageResult.OK) {
            //...
        } else {
            //...
        }
    }
}