Skip to main content
A newer version of this page is available. .

NavBarItem.Command Property

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

Namespace: DevExpress.Xpf.NavBar

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

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, simply 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}" />

The following code snippet (auto-collected from DevExpress Examples) contains a reference 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.

See Also