Επεξεργασία

Κοινή χρήση μέσω


InputBinding.CommandParameter Property

Definition

Gets or sets the command-specific data for a particular command.

public:
 property System::Object ^ CommandParameter { System::Object ^ get(); void set(System::Object ^ value); };
public object CommandParameter { get; set; }
member this.CommandParameter : obj with get, set
Public Property CommandParameter As Object

Property Value

The command-specific data. The default is null.

Remarks

The CommandParameter property is used to pass specific information to the command when it is executed. The type of the data is defined by the command. Many commands do not expect command parameters; for these commands, any command parameters passed will be ignored.

If the command that an input binding is associated with is a RoutedCommand, the CommandParameter of the input binding is passed to the RoutedCommand handlers through the ExecutedRoutedEventArgs and the CanExecuteRoutedEventArgs event data when the command is processed.

The data type and purpose of the command parameter are defined differently for each command and can be null. You can bind the Command, CommandParameter, and CommandTarget properties to an ICommand that is defined on an object. This enables you to define a custom command and associate it with user input. For more information, see the second example in InputBinding.

The InputBinding class does not support XAML usage because it does not expose a public parameterless constructor (it has a parameterless constructor, but it is protected). However, derived classes can expose a public constructor and therefore, can set properties that are inherited from InputBinding with XAML usage. Two existing InputBinding derived classes that can be instantiated in XAML and can set properties in XAML are KeyBinding and MouseBinding.

XAML Attribute Usage

<inputBindingDerivedClass CommandParameter="commandParameterString"/>  

XAML Property Element Usage

<inputBindingDerivedClass>  
  <inputBindingDerivedClass.CommandParameter>  
    <commandParameterObject/>  
  </inputBindingDerivedClass.CommandParameter>  
</inputBindingDerivedClass>  

XAML Values

inputBindingDerivedClass
A derived class of InputBinding that supports object element syntax, such as KeyBinding or MouseBinding. See Remarks.

commandParameterString
A string that is processed by a particular command. Strings are the common type used for command parameters because they can be easily set in XAML. For the expected string format and its purpose, see the documentation for the particular command that the input binding is associated with. Many commands do not expect parameters.

commandParameterObject
An object that is processed by a particular command. All existing WPF commands use strings. Therefore, this property element syntax is only relevant for custom command scenarios. In order to support this syntax, the commandParameterObject object must also support object element syntax (must have a public parameterless constructor).

Applies to