Skip to main content
All docs
V24.1

ConfirmationBehavior Class

Shows a confirmation message box before an application executes the specified command. Users can confirm or cancel the operation.

Namespace: DevExpress.Mvvm.UI

Assembly: DevExpress.Xpf.Core.v24.1.dll

NuGet Package: DevExpress.Wpf.Core

Declaration

public class ConfirmationBehavior :
    Behavior<DependencyObject>

Remarks

The following code sample attaches a command to a Button and enables a confirmation message for this command:

<UserControl x:Class="Example.View.MainView"
<!-- ... -->
    xmlns:ViewModel="clr-namespace:Example.ViewModel"
    xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
    <!-- ... -->
    <UserControl.Resources>
        <dxmvvm:BooleanNegationConverter x:Key="BooleanNegationConverter"/>
        <dxmvvm:BooleanToObjectConverter x:Key="BooleanToObjectConverter" TrueValue="Saved!" FalseValue="Unsaved!"/>
    </UserControl.Resources>

    <UserControl.DataContext>
        <ViewModel:MainViewModel/>
    </UserControl.DataContext>

    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <StackPanel Orientation="Horizontal">
            <Button Content="Save" Command="{Binding SaveCommand}"/>
            <Button Content="Close">
                <dxmvvm:Interaction.Behaviors>
                    <dxmvvm:ConfirmationBehavior EnableConfirmationMessage="{Binding IsSaved, Converter={StaticResource BooleanNegationConverter}}" 
                                                 Command="{Binding CloseCommand}" MessageText="The document has unsaved changes. Do you want to close the document?"/>
                </dxmvvm:Interaction.Behaviors>
            </Button>
            <TextBlock Text="{Binding IsSaved, Converter={StaticResource BooleanToObjectConverter}}"/>
        </StackPanel>
        <TextBox Text="{Binding Text, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Grid.Row="1"/>
    </Grid>
</UserControl>
using DevExpress.Mvvm;
using DevExpress.Mvvm.DataAnnotations;
// ...
    public class MainViewModel : ViewModelBase {

        string savedText;

        public string Text {
            get => GetValue<string>();
            set {
                SetValue(value);
                RaisePropertyChanged(nameof(IsSaved));
            }
        }
        // ...
        [Command]
        public void Close() {
            savedText = string.Empty;
            Text = string.Empty;
        }
    }

Run Demo: Behaviors Module in the WPF MVVM Demo

View Example

Customize a Confirmation Box

Property Desciption
Command Gets or sets the command that runs if the user accepts the confirmation message. This is a dependency property.
CommandPropertyName Gets or sets a name of an associated control’s command property. This is a dependency property.
CommandParameter Gets or sets parameters to pass to the Command. This is a dependency property.
EnableConfirmationMessage Gets or sets whether a confirmation message should be displayed. This is a dependency property.
MessageBoxService Gets or sets a custom message box service. You can use the WinUIMessageBox or create a custom message box that implements the IMessageBoxService interface. This is a dependency property.
MessageDefaultResult Gets or sets the confirmation message button that should be focused when the message appears. This is a dependency property.
MessageButton Gets or sets the confirmation message buttons. This is a dependency property.
MessageIcon Gets or sets the confirmation message icon. This is a dependency property.
MessageText Gets or sets the confirmation message text. This is a dependency property.
MessageTitle Gets or sets the confirmation message title. This is a dependency property.

Inheritance

Object
DispatcherObject
DependencyObject
Freezable
Animatable
DevExpress.Mvvm.UI.Interactivity.AttachableObjectBase
DevExpress.Mvvm.UI.Interactivity.Behavior
DevExpress.Mvvm.UI.Interactivity.Behavior<DependencyObject>
ConfirmationBehavior
See Also