Back to Devexpress

DXCommand

wpf-115776-mvvm-framework-dxbinding-dxcommand.md

latest1.4 KB
Original Source

DXCommand

  • Aug 25, 2021

DXCommand allows you to bind a command property to the method or property. The DevExpress binding mechanism requires special language expressions. Refer to the following topic for more information: Language Specification. The code sample below shows how to specify the Execute and CanExecute delegates.

xaml
<Button Content="OK" Command="{DXCommand Execute='Save(); Close()', CanExecute='CanSave() and CanClose()'}"/>

If you bind DXCommand.CanExecute to a property, you need to raise the PropertyChanged event to update the CanExecute state.

You can pass a parameter to the method that you call.

xaml
<TextBlock x:Name="tb" Text="text"/>
<Button Content="OK" Command="{DXCommand Execute='Save(@e(tb).Text)', CanExecute='CanSave(@e(tb).Text)'}"/>

Use the @parameter reserved word to access the CommandParameter value.

xaml
<TextBlock x:Name="tb" Text="text"/>
<Button Content="OK" Command="{DXCommand Execute='Save(@parameter)', CanExecute='CanSave(@parameter)'}" CommandParameter="{DXBinding @e(tb).Text}"/>

The DXCommand extension supports the “=” operator.

xaml
<Button Command="{DXCommand '@e(checkBox).IsChecked=true'}"/>