Intersoft ClientUI Documentation
RegisterClassCommandBinding Method
See Also  Send Feedback
Intersoft.Client.Framework.Input Namespace > CommandManager Class : RegisterClassCommandBinding Method






type
The class with which to register commandBinding.
commandBinding
The command binding to register.
Registers a CommandBinding with the specified type.

Syntax

Visual Basic (Declaration) 
Public Shared Sub RegisterClassCommandBinding( _
   ByVal type As Type, _
   ByVal commandBinding As CommandBinding _
) 
Visual Basic (Usage)Copy Code
Dim type As Type
Dim commandBinding As CommandBinding
 
CommandManager.RegisterClassCommandBinding(type, commandBinding)
C# 
public static void RegisterClassCommandBinding( 
   Type type,
   CommandBinding commandBinding
)
Delphi 
public procedure RegisterClassCommandBinding( 
    type: Type;
    commandBinding: CommandBinding
); static; 
JScript 
public static function RegisterClassCommandBinding( 
   type : Type,
   commandBinding : CommandBinding
);
Managed Extensions for C++ 
public: static void RegisterClassCommandBinding( 
   Type* type,
   CommandBinding* commandBinding
) 
C++/CLI 
public:
static void RegisterClassCommandBinding( 
   Type^ type,
   CommandBinding^ commandBinding
) 

Parameters

type
The class with which to register commandBinding.
commandBinding
The command binding to register.

Remarks

In addition to instance command binding, the commanding framework in ClientUI also supports class command binding API which is available in the CommandManager class. The class command binding is particularly useful when you have a fairly large amount of commands to bind to the controls.

The following code example shows how to use class command binding API to register a routed command on a specific type rather than an instance.

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 ClassCommandBinding : UXPage
    {
        public ClassCommandBinding()
        {
            // It is important to initialize the static EditingCommands class
            // before InitializeComponent is called
            EditingCommands.Initialize();
            InitializeComponent();
        }

        static ClassCommandBinding()
        {
            RoutedUICommand[] commands = new RoutedUICommand[] 
            {
                EditingCommands.Cut, EditingCommands.Copy, EditingCommands.Paste
            };

            // register class-level command binding for RoutedUICommand
            foreach (RoutedUICommand command in commands)
            {
                CommandManager.RegisterClassCommandBinding(
                    typeof(UXPage),
                    new CommandBinding(command, OnCommandExecuted, OnCanExecute));
            }
        }

        private static void OnCanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }

        private static void OnCommandExecuted(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: Use Class Binding to Implement a RoutedCommand.

Requirements

Target Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family

See Also

© 2012 All Rights Reserved.