Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
ICommandSource Interface
Collapse the table of content
Expand the table of content

ICommandSource Interface

Defines an object that knows how to invoke a command.

Namespace:  System.Windows.Input
Assembly:  PresentationCore (in PresentationCore.dll)

public interface ICommandSource

The ICommandSource type exposes the following members.

  NameDescription
Public propertyCommandGets the command that will be executed when the command source is invoked.
Public propertyCommandParameterRepresents a user defined data value that can be passed to the command when it is executed.
Public propertyCommandTargetThe object that the command is being executed on.
Top

The command source defines how a command is invoked by that particular object. For example, if a Button is associated with a command, the command is invoked when the Button is clicked.

A command source will normally disable itself if the command it is associated with cannot execute on the current command target. For example, a MenuItem associated with the Paste command will gray itself out when the Paste command cannot execute on the current command target.

Normally, a command source will listen to the CanExecuteChanged event on the command. This informs the command source when conditions change on the command target, such as loss of keyboard focus. The command source can then query the command using the CanExecute method.

Some of the classes in WPF that implement ICommandSource are: ButtonBase, MenuItem, and Hyperlink.

In the Windows Presentation Foundation (WPF) commanding system, the CommandTarget property on a ICommandSource is only applicable when the ICommand is a RoutedCommand. If the CommandTarget is set on a ICommandSource and the corresponding command is not a RoutedCommand, the command target is ignored.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft