Intersoft ClientUI Documentation
CommandBinding Class
Members 



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

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.

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

            <Intersoft:CommandManager.CommandBindings>
                <Intersoft:CommandBindingCollection>
                    <Intersoft:CommandBinding Command="Commands:EditingCommands.Cut"
                                              CanExecute="CutCmdCanExecute"
                                              Executed="CutExecuted"/>
                </Intersoft:CommandBindingCollection>
            </Intersoft:CommandManager.CommandBindings>

            <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:UXToolBar>
                <Intersoft:UXTextBox Name="textBox1" Text="Type your text here..." Intersoft:DockPanel.IsFillElement="True" />
            </Intersoft:DockPanel>

        </Grid>

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

C#
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
            EditingCommands.Initialize();
            InitializeComponent();
        }

        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

System.Object
   Intersoft.Client.Framework.Input.CommandBinding
      Intersoft.Client.Framework.Input.HybridCommandBinding

Requirements

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

Reference

CommandBinding Members
Intersoft.Client.Framework.Input Namespace

Send Feedback