Back to Devexpress

CommandItem Class

wpf-devexpress-dot-mvvm-dot-ui-e9d778bd.md

latest5.2 KB
Original Source

CommandItem Class

A command that the CompositeCommandBehavior aggregates to create a composite command.

Namespace : DevExpress.Mvvm.UI

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

NuGet Package : DevExpress.Wpf.Core

Declaration

csharp
public class CommandItem :
    DependencyObjectExt
vb
Public Class CommandItem
    Inherits DependencyObjectExt

Remarks

Each CommandItem should contain the Command property that is the ICommand that the behavior should aggregate.

In the following code sample, the CompositeCommandBehavior takes two CommandItems , aggregates them to the CompositeCommand, and executes it when a user clicks the ThemedWindow‘s back button:

xaml
<dx:ThemedWindow ...
    xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
    xmlns:ViewModels="clr-namespace:CompositeCommandCommandPropertyName.ViewModels"
    xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
    ShowBackButton="True">
    <dx:ThemedWindow.DataContext>
        <ViewModels:MainViewModel/>
    </dx:ThemedWindow.DataContext>
    <dxmvvm:Interaction.Behaviors>
        <dxmvvm:CompositeCommandBehavior CommandPropertyName="NavigateBackCommand">
            <dxmvvm:CommandItem Command="{Binding SaveCommand}"/>
            <dxmvvm:CommandItem Command="{Binding CloseCommand}"/>
        </dxmvvm:CompositeCommandBehavior>
    </dxmvvm:Interaction.Behaviors>
    <!-- ... -->
</dx:ThemedWindow>
csharp
using DevExpress.Mvvm;
using DevExpress.Mvvm.DataAnnotations;
using System.Windows;

public partial class MainViewModel : ViewModelBase {

    [Command]
    public void Save()
    {
      // ...
    }

    [Command]
    public void Close()
    {
      // ...
    }
}
vb
Imports DevExpress.Mvvm
Imports DevExpress.Mvvm.DataAnnotations
Imports System.Windows

Public Partial Class MainViewModel
    Inherits ViewModelBase

    <Command>
    Public Sub Save()
        ' ...
    End Sub

    <Command>
    Public Sub Close()
        ' ...
    End Sub
End Class

The following code snippets (auto-collected from DevExpress Examples) contain references to the CommandItem class.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-bind-gridcontrol-to-dynamic-data/CS/ITypedList/MainWindow.xaml#L28

xml
<dxmvvm:CompositeCommandBehavior>
    <dxmvvm:CommandItem Command="{Binding AddColumnCommand}" />
    <dxmvvm:CommandItem Command="{DXCommand '@e(Grid).PopulateColumns()'}" />

wpf-data-grid-specify-row-visibility-in-viewmodel/CS/CustomFilteringMVVM/MainWindow.xaml#L42

xml
<dxmvvm:CompositeCommandBehavior>
    <dxmvvm:CommandItem Command="{Binding AddExclusionCommand}"/>
    <dxmvvm:CommandItem Command="{DXCommand Execute='@e(grid).RefreshData()'}" />

wpf-scheduler-create-regular-and-recurring-appointments-at-view-model-level/CS/DXApplication14/MainWindow.xaml#L22

xml
<dxmvvm:CompositeCommandBehavior CanExecuteCondition="AnyCommandCanBeExecuted">
    <dxmvvm:CommandItem Command="{Binding AddApptCommand}"
                        CommandParameter="false" />

Inheritance

Object DispatcherObject DependencyObject Freezable DevExpress.Mvvm.UI.Native.DependencyObjectExt CommandItem

See Also

CommandItem Members

DevExpress.Mvvm.UI Namespace