Intersoft ClientUI Documentation
CanExecuteRoutedEventArgs Class
Members  See Also  Send Feedback
Intersoft.Client.Framework.Input Namespace : CanExecuteRoutedEventArgs Class






Provides data for the CanExecute and PreviewCanExecute routed events.

Object Model

CanExecuteRoutedEventArgs Class

Syntax

Visual Basic (Declaration) 
Public NotInheritable Class CanExecuteRoutedEventArgs 
   Inherits Intersoft.Client.Framework.ISRoutedEventArgs
Visual Basic (Usage)Copy Code
Dim instance As CanExecuteRoutedEventArgs
C# 
public sealed class CanExecuteRoutedEventArgs : Intersoft.Client.Framework.ISRoutedEventArgs 
Delphi 
public class CanExecuteRoutedEventArgs = class(Intersoft.Client.Framework.ISRoutedEventArgs)sealed; 
JScript 
public sealed class CanExecuteRoutedEventArgs extends Intersoft.Client.Framework.ISRoutedEventArgs
Managed Extensions for C++ 
public __gc __sealed class CanExecuteRoutedEventArgs : public Intersoft.Client.Framework.ISRoutedEventArgs 
C++/CLI 
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 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.