The CommandManager and our RoutedCommand implementation for Silverlight was originally intended for internal use as a compatibility layer for the development of RadScheduler and RadDocking, hence it is not documented and advertized. This is slowly changing now, since we are providing more controls that use commands - Buttons, Menu, ContextMenu, etc. Here is a simple example, demonstrating the basic use of our command framework:
Since it was intended to be as compatible as possible to the WPF command framework, its usage is virtually the same, with only a few differences:
- the command instances (the static class MyCommands from the example above) must be initialized before the XAML parser is executed. This is because the parser has some limitations and cannot correctly parse the XAML representation of the commands. In two words, you should "touch" a static property of the commands class before the InitializeComponent() call.
- when a command is created, you should set its Name to be the same as the name that will be used in XAML. Again, this is because of the limitations of the Silverlight parser. In other words, if you want to write the following XAML:
<RadButton ... Command="local:MyCommands.Copy" ... />
you should have a static class named MyCommands, that registered a command, named Copy:
public static class MyCommands
public static readonly RoutedCommand Copy =
new RoutedUICommand("Copy", typeof(MyCommands));
The name of the property, holding the command instance actually does not matter, but I would recommend naming it after the command because the syntax implies that they are the same.
- you add command bindings using the attached property CommandManager.CommandBindings. Instead, you could directly add event handlers to CanExecute and Executed as we do in the example above.
- you add input bindings using the attached property CommandManager.InputBindings.
Please, let us know if you need additional information.
the Telerik team