Skip to main content
All docs
V24.2

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

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.v24.2.dll

NuGet Package: DevExpress.Wpf.Core

#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;
    }
} 

#Limitations

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

See Also