I am working with a DevExpress GridControl (version 16.1), and I have a column for ExecutionTime that is bound to a DateTime property (Model.ExecutionTime). I want to:
- Remove the dropdown (calendar) from the editor and make it
text-editable. - Apply a mask (MM-dd-yyyy HH:mm:ss.fff) to enforce a specific format.
- Trigger an event after the value is changed and pass the current
row’s data to the ViewModel command.
To achieve this, I used TextEditSettings as the editor for the column and attached dxmvvm:Interaction.Behaviors to trigger the event. However, I am facing two issues:
- When I attach the behaviors inside TextEditSettings, the
EventToCommand is not triggered. - When I attach the behaviors outside the TextEditSettings, the event
triggers, but the CommandParameter (RowData.Row) is null.
Current Implementation:
Here’s the current setup I am using:
Case 1: Behaviors Inside TextEditSettings (Event Not Triggered):
<code><dxg:GridColumn Header="Ex.Time" FieldName="Model.ExecutionTime" Width="120">
<dxg:GridColumn.EditSettings>
<dxe:TextEditSettings
Mask="MM-dd-yyyy HH:mm:ss.fff"
MaskType="DateTime">
<dxmvvm:Interaction.Behaviors>
<dxmvvm:EventToCommand
EventName="Validate"
Command="{Binding DataContext.TradeCommandVm.ExecutionTimeCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
CommandParameter="{Binding DataContext.SelectedTrade, Mode=TwoWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" />
</dxmvvm:Interaction.Behaviors>
</dxe:TextEditSettings>
</dxg:GridColumn.EditSettings>
</dxg:GridColumn>
Case 2: Behaviors Outside TextEditSettings (Event Triggered, but ExecutionTime is Null):
<dxg:GridColumn Header="Ex.Time" FieldName="Model.ExecutionTime" Width="120">
<dxg:GridColumn.EditSettings>
<dxe:TextEditSettings
Mask="MM-dd-yyyy HH:mm:ss.fff"
MaskType="DateTime" />
</dxg:GridColumn.EditSettings>
<dxmvvm:Interaction.Behaviors>
<dxmvvm:EventToCommand
EventName="Validate"
Command="{Binding DataContext.TradeCommandVm.ExecutionTimeCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
CommandParameter="{Binding DataContext.SelectedTrade, Mode=TwoWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" >
</dxmvvm:EventToCommand>
</dxmvvm:Interaction.Behaviors>
</dxg:GridColumn>
I would appreciate any guidance or suggestions on how to correctly trigger the event or a similar mechanism within TextEditSettings, or alternative approaches to achieve this functionality. Thank you in advance for your help!
</code>
<code><dxg:GridColumn Header="Ex.Time" FieldName="Model.ExecutionTime" Width="120">
<dxg:GridColumn.EditSettings>
<dxe:TextEditSettings
Mask="MM-dd-yyyy HH:mm:ss.fff"
MaskType="DateTime">
<dxmvvm:Interaction.Behaviors>
<dxmvvm:EventToCommand
EventName="Validate"
Command="{Binding DataContext.TradeCommandVm.ExecutionTimeCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
CommandParameter="{Binding DataContext.SelectedTrade, Mode=TwoWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" />
</dxmvvm:Interaction.Behaviors>
</dxe:TextEditSettings>
</dxg:GridColumn.EditSettings>
</dxg:GridColumn>
Case 2: Behaviors Outside TextEditSettings (Event Triggered, but ExecutionTime is Null):
<dxg:GridColumn Header="Ex.Time" FieldName="Model.ExecutionTime" Width="120">
<dxg:GridColumn.EditSettings>
<dxe:TextEditSettings
Mask="MM-dd-yyyy HH:mm:ss.fff"
MaskType="DateTime" />
</dxg:GridColumn.EditSettings>
<dxmvvm:Interaction.Behaviors>
<dxmvvm:EventToCommand
EventName="Validate"
Command="{Binding DataContext.TradeCommandVm.ExecutionTimeCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
CommandParameter="{Binding DataContext.SelectedTrade, Mode=TwoWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" >
</dxmvvm:EventToCommand>
</dxmvvm:Interaction.Behaviors>
</dxg:GridColumn>
I would appreciate any guidance or suggestions on how to correctly trigger the event or a similar mechanism within TextEditSettings, or alternative approaches to achieve this functionality. Thank you in advance for your help!
</code>
<dxg:GridColumn Header="Ex.Time" FieldName="Model.ExecutionTime" Width="120">
<dxg:GridColumn.EditSettings>
<dxe:TextEditSettings
Mask="MM-dd-yyyy HH:mm:ss.fff"
MaskType="DateTime">
<dxmvvm:Interaction.Behaviors>
<dxmvvm:EventToCommand
EventName="Validate"
Command="{Binding DataContext.TradeCommandVm.ExecutionTimeCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
CommandParameter="{Binding DataContext.SelectedTrade, Mode=TwoWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" />
</dxmvvm:Interaction.Behaviors>
</dxe:TextEditSettings>
</dxg:GridColumn.EditSettings>
</dxg:GridColumn>
Case 2: Behaviors Outside TextEditSettings (Event Triggered, but ExecutionTime is Null):
<dxg:GridColumn Header="Ex.Time" FieldName="Model.ExecutionTime" Width="120">
<dxg:GridColumn.EditSettings>
<dxe:TextEditSettings
Mask="MM-dd-yyyy HH:mm:ss.fff"
MaskType="DateTime" />
</dxg:GridColumn.EditSettings>
<dxmvvm:Interaction.Behaviors>
<dxmvvm:EventToCommand
EventName="Validate"
Command="{Binding DataContext.TradeCommandVm.ExecutionTimeCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
CommandParameter="{Binding DataContext.SelectedTrade, Mode=TwoWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" >
</dxmvvm:EventToCommand>
</dxmvvm:Interaction.Behaviors>
</dxg:GridColumn>
I would appreciate any guidance or suggestions on how to correctly trigger the event or a similar mechanism within TextEditSettings, or alternative approaches to achieve this functionality. Thank you in advance for your help!