Partage via


InputBinding.Command Propriété

Définition

Obtient ou définit la ICommand associée à cette liaison d’entrée.

public:
 property System::Windows::Input::ICommand ^ Command { System::Windows::Input::ICommand ^ get(); void set(System::Windows::Input::ICommand ^ value); };
[System.ComponentModel.TypeConverter("System.Windows.Input.CommandConverter, PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null")]
[System.Windows.Localizability(System.Windows.LocalizationCategory.NeverLocalize)]
public System.Windows.Input.ICommand Command { get; [System.Security.SecurityCritical] set; }
[System.Windows.Localizability(System.Windows.LocalizationCategory.NeverLocalize)]
[System.ComponentModel.TypeConverter("System.Windows.Input.CommandConverter, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null")]
public System.Windows.Input.ICommand Command { get; set; }
[<System.ComponentModel.TypeConverter("System.Windows.Input.CommandConverter, PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null")>]
[<System.Windows.Localizability(System.Windows.LocalizationCategory.NeverLocalize)>]
[<set: System.Security.SecurityCritical>]
member this.Command : System.Windows.Input.ICommand with get, set
[<System.Windows.Localizability(System.Windows.LocalizationCategory.NeverLocalize)>]
[<System.ComponentModel.TypeConverter("System.Windows.Input.CommandConverter, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null")>]
member this.Command : System.Windows.Input.ICommand with get, set
Public Property Command As ICommand

Valeur de propriété

Commande associée.

Attributs

Exceptions

La valeur Command est null.

Exemples

L’exemple suivant montre comment utiliser un KeyBinding pour lier un KeyGesture à la commande ApplicationCommands.Open. Lorsque le mouvement de clé est effectué, la commande Open est appelée.

<Window.InputBindings>
  <KeyBinding Key="B"
              Modifiers="Control" 
              Command="ApplicationCommands.Open" />
</Window.InputBindings>
KeyGesture OpenKeyGesture = new KeyGesture(
    Key.B,
    ModifierKeys.Control);

KeyBinding OpenCmdKeybinding = new KeyBinding(
    ApplicationCommands.Open,
    OpenKeyGesture);

this.InputBindings.Add(OpenCmdKeybinding);
Dim OpenKeyGesture As New KeyGesture(Key.B, ModifierKeys.Control)

Dim OpenCmdKeybinding As New KeyBinding(ApplicationCommands.Open, OpenKeyGesture)

Me.InputBindings.Add(OpenCmdKeybinding)

Remarques

La classe InputBinding ne prend pas en charge l’utilisation XAML, car elle n’expose pas de constructeur sans paramètre public (il a un constructeur sans paramètre, mais il est protégé). Toutefois, les classes dérivées peuvent exposer un constructeur public et, par conséquent, utiliser des propriétés héritées de InputBinding. Deux classes dérivées InputBinding existantes qui peuvent être instanciées en XAML et qui peuvent définir des propriétés avec des utilisations XAML sont KeyBinding et MouseBinding.

ICommand fait référence à un convertisseur de type qui permet à certaines implémentations ICommand préexistantes de spécifier des valeurs sous la forme d’une chaîne. Ce comportement de conversion de type définit la forme de valeur d’attribut de cette propriété. Vous pouvez également lier les propriétés Command, CommandParameteret CommandTarget à un ICommand défini sur un objet. Cela vous permet de définir une commande personnalisée et de l’associer à l’entrée utilisateur. Pour plus d’informations, consultez le deuxième exemple dans InputBinding.

Utilisation des attributs XAML

< inputBindingDerivedClass Command= »ICommand« />

Utilisation de l’élément de propriété XAML

<inputBindingDerivedClass>  
  <inputBindingDerivedClass.Command>  
    <iCommandImplementation/>  
  </inputBindingDerivedClass.Command>  
</inputBindingDerivedClass>  

Valeurs XAML

inputBindingDerivedClass
Classe dérivée de InputBinding qui prend en charge la syntaxe de l’élément objet, telle que KeyBinding ou MouseBinding. Voir les remarques.

iCommandImplementation
Implémentation d’objet de ICommand qui prend en charge la syntaxe des éléments d’objet (a un constructeur sans paramètre public).

S’applique à

Voir aussi