CanExecuteRoutedEventArgs CanExecuteRoutedEventArgs CanExecuteRoutedEventArgs CanExecuteRoutedEventArgs Class

Definition

Provides data for the CanExecute and PreviewCanExecute routed events.

public ref class CanExecuteRoutedEventArgs sealed : System::Windows::RoutedEventArgs
public sealed class CanExecuteRoutedEventArgs : System.Windows.RoutedEventArgs
type CanExecuteRoutedEventArgs = class
    inherit RoutedEventArgs
Public NotInheritable Class CanExecuteRoutedEventArgs
Inherits RoutedEventArgs
Inheritance
CanExecuteRoutedEventArgsCanExecuteRoutedEventArgsCanExecuteRoutedEventArgsCanExecuteRoutedEventArgs

Examples

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;
    }
}
' CanExecuteRoutedEventHandler that only returns true if
' the source is a control.
Private Sub CanExecuteCustomCommand(ByVal sender As Object, ByVal e As CanExecuteRoutedEventArgs)
	Dim target As Control = TryCast(e.Source, Control)

	If target IsNot Nothing Then
		e.CanExecute = True
	Else
		e.CanExecute = False
	End If
End Sub

Remarks

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.

Properties

CanExecute CanExecute CanExecute CanExecute

Gets or sets a value that indicates whether the RoutedCommand associated with this event can be executed on the command target.

Command Command Command Command

Gets the command associated with this event.

ContinueRouting ContinueRouting ContinueRouting ContinueRouting

Determines whether the input routed event that invoked the command should continue to route through the element tree.

Handled Handled Handled Handled

Gets or sets a value that indicates the present state of the event handling for a routed event as it travels the route.

(Inherited from RoutedEventArgs)
OriginalSource OriginalSource OriginalSource OriginalSource

Gets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class.

(Inherited from RoutedEventArgs)
Parameter Parameter Parameter Parameter

Gets the command specific data.

RoutedEvent RoutedEvent RoutedEvent RoutedEvent

Gets or sets the RoutedEvent associated with this RoutedEventArgs instance.

(Inherited from RoutedEventArgs)
Source Source Source Source

Gets or sets a reference to the object that raised the event.

(Inherited from RoutedEventArgs)

Methods

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
InvokeEventHandler(Delegate, Object) InvokeEventHandler(Delegate, Object) InvokeEventHandler(Delegate, Object) InvokeEventHandler(Delegate, Object)

When overridden in a derived class, provides a way to invoke event handlers in a type-specific way, which can increase efficiency over the base implementation.

(Inherited from RoutedEventArgs)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
OnSetSource(Object) OnSetSource(Object) OnSetSource(Object) OnSetSource(Object)

When overridden in a derived class, provides a notification callback entry point whenever the value of the Source property of an instance changes.

(Inherited from RoutedEventArgs)
ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to

See also