CanExecuteRoutedEventArgs Class
Provides data for the CanExecute and PreviewCanExecute routed events.
Assembly: PresentationCore (in PresentationCore.dll)
Typically, a command source, such a MenuItem, 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 MenuItem is acting as the command source for a command and the command cannot execute on the current command target, then the MenuItem will gray itself out.
The CanExecuteChanged event notifies a command source when the ability of a command to execute may have changed.
The follow example creates a CanExecuteRoutedEventHandler that returns true only if the command target is a control. First, Source is cast to a Control. If Source is a Control, CanExecute is set to true; otherwise, it is set to false.
// CanExecuteRoutedEventHandler that only returns true if // the source is a control. private void CanExecuteCustomCommand(object sender, CanExecuteRoutedEventArgs e) { Control target = e.Source as Control; if(target != null) { e.CanExecute = true; } else { e.CanExecute = false; } }
System.EventArgs
System.Windows.RoutedEventArgs
System.Windows.Input.CanExecuteRoutedEventArgs
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.