Intersoft.Client.Framework.Input Namespace > CommandManager Class : RegisterClassCommandBinding Method |
Public Shared Sub RegisterClassCommandBinding( _ ByVal type As Type, _ ByVal commandBinding As CommandBinding _ )
Dim type As Type Dim commandBinding As CommandBinding CommandManager.RegisterClassCommandBinding(type, commandBinding)
public static void RegisterClassCommandBinding( Type type, CommandBinding commandBinding )
public: static void RegisterClassCommandBinding( Type^ type, CommandBinding^ commandBinding )
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); } } } |
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