Intersoft ClientUI Documentation
CommandBinding Class

Binds a RoutedCommand to the event handlers that implement the command.
Public Class CommandBinding 
Dim instance As CommandBinding
public class CommandBinding 
public ref class CommandBinding 

A CommandBinding associates a command with the PreviewExecuted / Executed and PreviewCanExecute / CanExecute events which implement and determine the status of the command.

When the Execute or CanExecute method of a RoutedCommand is called, the PreviewExecuted / Executed or the PreviewCanExecute / CanExecute events are raised on the command target. If the command target has a CommandBinding for the command, the appropriate handlers are called. If the command target does not have a CommandBinding for the command, the events are routed through the element tree until an element that has a CommandBinding is found.

The following code example illustrates the big picture of these processes and shows how the routed command and command binding can be easily defined in XAML.

Copy Code
        <Grid x:Name="LayoutRoot">

                    <Intersoft:CommandBinding Command="Commands:EditingCommands.Cut"

            <Intersoft:DockPanel Name="dockPanel1" FillChildMode="Custom">
                <Intersoft:UXToolBar Name="toolBar1" Intersoft:DockPanel.Dock="Top">
                    <Intersoft:UXToolBarButton Name="btn_Cut" Command="Commands:EditingCommands.Cut" DisplayMode="Image" Icon="../Images/CutHS.png" ToolTipService.ToolTip="Cut"/>
                <Intersoft:UXTextBox Name="textBox1" Text="Type your text here..." Intersoft:DockPanel.IsFillElement="True" />


The following code example shows the event handler for the CanExecute and Executed routed event for the CommandBinding associated to the Cut command.

Copy Code
using System.Windows;
using ClientUIApplication_Docs.Commands;
using Intersoft.Client.Framework.Input;
using Intersoft.Client.UI.Navigation;

namespace ClientUIApplication_Docs.RoutedCommands
    public partial class CommandOverview : UXPage
        public CommandOverview()
            // It is important to initialize the static EditingCommands class
            // before InitializeComponent is called

        private void CutCmdCanExecute(object sender, CanExecuteRoutedEventArgs e)
            e.CanExecute = true;

        private void CutExecuted(object sender, ExecutedRoutedEventArgs e)
            string command = ((RoutedCommand)e.Command).Name;
            string target = ((FrameworkElement)e.OriginalSource).Name;

            MessageBox.Show("The " + command +  " command has been invoked on target object " + target);

For a more complete version of this example, see How-to: Implement a RoutedCommand. To learn more about commanding, see Commanding Overview.

Inheritance Hierarchy



Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also


CommandBinding Members
Intersoft.Client.Framework.Input Namespace

Send Feedback