All docs
V21.2
21.2
21.1
20.2
The page you are viewing does not exist in version 20.2. This link will take you to the root page.
20.1
The page you are viewing does not exist in version 20.1. This link will take you to the root page.
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

IEventArgsTwoWayConverter Interface

Allows you to convert an event’s arguments to a command’s parameter and vice versa.

Namespace: DevExpress.Mvvm.UI

Assembly: DevExpress.Xpf.Core.v21.2.dll

Declaration

public interface IEventArgsTwoWayConverter :
    IEventArgsConverter

Remarks

Event Args Back Conversion

The EventToCommand behavior uses the EventArgsConverter property to pass event arguments to a command. If you need to take the arguments back from the command to the event, you can implement the IEventArgsTwoWayConverter in your converter class.

The IEventArgsTwoWayConverter extends the IEventArgsConverter interface and contains the ConvertBack method that is called after the command execution. This method accepts the performed command’s result as a parameter and allows you to pass this result to the event arguments.

You can inherit your converter class from the EventArgsConverterBase<TArgs> class that already implements the IEventArgsTwoWayConverter interface. Override the ConvertBack method and define the required logic.

The code sample below uses the back conversion to validate data:

<dxe:TextEdit EditValue="{Binding UserName}">
    <dxmvvm:Interaction.Behaviors>
      <dxmvvm:EventToCommand Command="{Binding UserNameValidationCommand}"
                             EventArgsConverter="{local:ValidateEventArgsConverter}"
                             EventName="Validate"/>
    </dxmvvm:Interaction.Behaviors>
</dxe:TextEdit>
public class ValidationArgs {
    public string ErrorContent { get; private set; }
    public object Value { get; }

    public ValidationArgs(object value) => Value = value;
    public void SetError(bool isValid, string errorContent) => ErrorContent = isValid ? null : errorContent;
}

public class ValidateEventArgsConverter : EventArgsConverterBase<ValidationEventArgs> {
    protected override object Convert(object sender, ValidationEventArgs e) => new ValidationArgs(e.Value);
    protected override void ConvertBack(object sender, ValidationEventArgs e, object parameter) {
        var args = parameter as ValidationArgs;
        e.IsValid = args.ErrorContent == null;
        e.ErrorContent = args.ErrorContent;
    }
} 

View Example: How to Use Two Way Conversion

Limitations

Two-way conversion requires the command to be executed immediately. You cannot use a Dispatcher that delays the command execution.

See Also