Intersoft ClientUI Documentation
CanExecuteRoutedEventArgs Class
Members 



Provides data for the CanExecute and PreviewCanExecute routed events.
Object Model
CanExecuteRoutedEventArgs ClassRoutedEvent Class
Syntax
Public NotInheritable Class CanExecuteRoutedEventArgs 
   Inherits Intersoft.Client.Framework.ISRoutedEventArgs
Dim instance As CanExecuteRoutedEventArgs
public sealed class CanExecuteRoutedEventArgs : Intersoft.Client.Framework.ISRoutedEventArgs 
public ref class CanExecuteRoutedEventArgs sealed : public Intersoft.Client.Framework.ISRoutedEventArgs 
Remarks

Typically, a command source, such as UXButton, will call the CanExecute method on a RoutedCommand to determine if the command can or cannot execute on the current command target. If CanExecute is set to false from an event handler, the command source will disable itself. For example, if a UXButton is acting as the command source for a command and the command cannot execute on the current command target, then the UXButton will gray itself out.

The CanExecuteChanged event notifies a command source when the ability of a command to execute may have changed. For more information about routed command support in ClientUI, see Commanding Overview.

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.

Inheritance Hierarchy

System.Object
   System.EventArgs
      System.Windows.RoutedEventArgs
         Intersoft.Client.Framework.ISRoutedEventArgs
            Intersoft.Client.Framework.Input.CanExecuteRoutedEventArgs

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

CanExecuteRoutedEventArgs Members
Intersoft.Client.Framework.Input Namespace

Concepts

Commanding Overview

Send Feedback