Back to Devexpress

BarItem.Command Property

wpf-devexpress-dot-xpf-dot-bars-dot-baritem-d990d14b.md

latest6.9 KB
Original Source

BarItem.Command Property

Gets or sets the command to invoke when the bar item is clicked. This is a dependency property.

Namespace : DevExpress.Xpf.Bars

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

NuGet Package : DevExpress.Wpf.Core

Declaration

csharp
[Bindable(true)]
public ICommand Command { get; set; }
vb
<Bindable(True)>
Public Property Command As ICommand

Property Value

TypeDescription
ICommand

The command to invoke when the bar item is clicked.

|

Remarks

When invoking the bar item’s functionality, the command is executed first. Then, the BarItem.ItemClick and BarManager.ItemClick events fire.

Use the BarItem.BeforeCommandExecute property to perform actions immediately after an end-user has clicked the button before the Command is executed.

Example

This example shows how to specify a command and custom short cut for a bar item. A command and short cut are assigned to the item via the Command and KeyGesture properties, respectively. In the example, a bar is docked to the BarContainerControl which is created manually.

xaml
<dxb:BarManager.Items>                
    <dxb:BarButtonItem Name="btnCut" 
                       Command="ApplicationCommands.Cut" 
                       KeyGesture="CTRL+1" 
                       CommandTarget="{Binding ElementName=textBox}" 
                       Content="{Binding Command.Text, RelativeSource={RelativeSource Self}}"/>
</dxb:BarManager.Items>

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

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-spreadsheet-bind-spreadsheet-to-ms-sql-server-database/CS/WpfSpreadsheet_BindToDataSource/MainWindow.xaml#L21

xml
<dxb:BarManager.Items>
    <dxb:BarButtonItem x:Name="biFileNew" Command="{Binding FileNew, Mode=OneTime, Source={StaticResource commands}}" />
    <dxb:BarButtonItem x:Name="biFileOpen" Command="{Binding FileOpen, Mode=OneTime, Source={StaticResource commands}}" />

wpf-spreadsheet-assign-custom-in-place-editors/CS/WpfSpreadsheet_CustomCellEditors/MainWindow.xaml#L22

xml
<dxb:BarManager.Items>
    <dxb:BarButtonItem x:Name="biFileNew" Command="{Binding FileNew, Mode=OneTime, Source={StaticResource commands}}" />
    <dxb:BarButtonItem x:Name="biFileOpen" Command="{Binding FileOpen, Mode=OneTime, Source={StaticResource commands}}" />

wpf-spreadsheet-bind-a-worksheet-to-generic-list-or-bindinglist-data-source/CS/DataBindingToListExample/MainWindow.xaml#L16

xml
<dxb:BarManager.Items>
    <dxb:BarButtonItem x:Name="biFileNew" Command="{Binding FileNew, Mode=OneTime, Source={StaticResource commands}}"/>
    <dxb:BarButtonItem x:Name="biFileOpen" Command="{Binding FileOpen, Mode=OneTime, Source={StaticResource commands}}"/>

wpf-data-grid-implement-crud-operations/CS/CodeBehind/EFCore/LocalData/MainWindow.xaml#L14

xml
<dxb:ToolBarControl>
    <dxb:BarButtonItem Content="Refresh (F5)" Command="{Binding View.Commands.RefreshDataSource, ElementName=grid}"
                       Glyph="{dx:DXImage SvgImages/Icon Builder/Actions_Refresh.svg}" BarItemDisplayMode="ContentAndGlyph" />

wpf-data-grid-extend-crud-operations/CS/AsyncCRUDOperations/MainWindow.xaml#L15

xml
<dxb:ToolBarControl>
    <dxb:BarButtonItem Content="Refresh (F5)" Command="{Binding View.Commands.RefreshDataSource, ElementName=grid}" Glyph="{dx:DXImage SvgImages/Icon Builder/Actions_Refresh.svg}" BarItemDisplayMode="ContentAndGlyph" />
    <dxb:BarButtonItem Content="Edit (F2)" Command="{Binding View.Commands.EditFocusedRow, ElementName=grid}" Glyph="{dx:DXImage SvgImages/Icon Builder/Actions_Edit.svg}" BarItemDisplayMode="ContentAndGlyph" />

wpf-pdf-viewer-customize-the-popup-menu/CS/MainWindow.xaml.cs#L30

csharp
barButtonItem.Content = "Save As...";
barButtonItem.Command = viewer.SaveAsCommand;
InsertAction insertBarButtonItem = new InsertAction();

wpf-pdf-viewer-customize-the-popup-menu/VB/MainWindow.xaml.vb#L32

vb
barButtonItem.Content = "Save As..."
barButtonItem.Command = viewer.SaveAsCommand
Dim insertBarButtonItem As New InsertAction()

See Also

KeyGesture

BarItem.ItemClick

BarManager.ItemClick

PerformClick()

CommandParameter

CommandTarget

BarItem Class

BarItem Members

DevExpress.Xpf.Bars Namespace