Skip to main content

NavBarItem.Command Property

Gets or sets the command to invoke when the NavBar item is clicked.

Namespace: DevExpress.Xpf.NavBar

Assembly: DevExpress.Xpf.NavBar.v23.2.dll

NuGet Package: DevExpress.Wpf.NavBar

Declaration

[Bindable(true)]
public ICommand Command { get; set; }

Property Value

Type Description
ICommand

An ICommand object to invoke when the NavBar item is clicked.

Remarks

If a NavBarItem was selected via a click at runtime, a Command is executed and the NavBarItem.Select and NavBarItem.Click events fire. If an end-user clicks an already selected item, the NavBarItem.Select event is skipped.

The Command can receive additional custom parameters (specified via the NavBarItem.CommandParameter) and a target object on which the command is executed (specified via the NavBarItem.CommandTarget).

The code below illustrates an example of defining a command:

xmlns:custom="clr-namespace:myApplicationNamespace">
<Window.CommandBindings>
    <CommandBinding Command="{x:Static custom:MainWindow.myCommand}"
                Executed="myCommandExecuted"
                CanExecute="myCommandExecute"/>
</Window.CommandBindings> 
namespace myApplicationNamespace {
    public partial class MainWindow : Window {
        public static RoutedCommand myCommand = new RoutedCommand();
        public MainWindow() {
            InitializeComponent();
        }
        private void myCommandExecuted(object sender, ExecutedRoutedEventArgs e) {
            //Actions to perform
            . . .
        }
        private void myCommandExecute(object sender, CanExecuteRoutedEventArgs e) {
            //Case of command's availability
            if (. . .) {
                e.CanExecute = true; }
        }
    }
}

To use the command as the user clicks a NavBarItem, assign it to the Command property of this group as in the following code:

<dxn:NavBarGroup Content="My Group" Name="navBarGroup1" Command="{x:Static custom:MainWindow.myCommand}" />
See Also