Intersoft.Client.Framework.Input Namespace : CanExecuteRoutedEventHandler Delegate |
Public Delegate Sub CanExecuteRoutedEventHandler( _ ByVal sender As Object, _ ByVal e As CanExecuteRoutedEventArgs _ )
Dim instance As New CanExecuteRoutedEventHandler(AddressOf HandlerMethod)
public delegate void CanExecuteRoutedEventHandler( object sender, CanExecuteRoutedEventArgs e )
public delegate void CanExecuteRoutedEventHandler( Object^ sender, CanExecuteRoutedEventArgs^ e )
The CanExecuteRoutedEventHandler determines if the command associated with the event source is able to execute on the command target. If the command has a command source that specifies a target, then the target information can be obtained through sender. If the CommandTarget is not set, the element with keyboard focus is the target, and can also be obtained through sender. If it is determined that the command can execute on the target, then the CanExecute property should be set to true; otherwise, set it to false
The following example creates a CanExecuteRoutedEventHandler that returns true only if the text box has valid selection. Consequently, the command sources that bound to the particular command will be automatically enabled or disabled based on the value specified in the CanExecute property of the event argument.
C# |
Copy Code
|
---|---|
private static void OnCanExecute(object sender, CanExecuteRoutedEventArgs e) { EditorCommandInterface page = sender as EditorCommandInterface; // The e.CanExecute provides feedback to the associated caller whether the // e.Command can be executed. If the value is false, the UI will be automatically disabled // thus enables consistent and reliable command interface. if (page == null) { e.CanExecute = false; return; } if (e.Command == EditingCommands.Cut || e.Command == EditingCommands.Copy) { // Enable Cut or Copy command if the textbox has selection e.CanExecute = page.textBox1.Selection != null && !string.IsNullOrEmpty(page.textBox1.Selection.Text); } else if (e.Command == EditingCommands.Paste) { // Enable Paste command if the Clipboard has a valid text e.CanExecute = page.textBox1.Selection != null && Clipboard.ContainsText(); } else { e.CanExecute = true; } } |
For a more complete version of this example, see How-to: Implement Rich Editor Command Interface with ToolBar, MenuBar and ContextMenu.
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