InputBinding.CommandTarget 屬性

定義

取得或設定命令的目標項目。Gets or sets the target element of the command.

public:
 property System::Windows::IInputElement ^ CommandTarget { System::Windows::IInputElement ^ get(); void set(System::Windows::IInputElement ^ value); };
public System.Windows.IInputElement CommandTarget { get; set; }
member this.CommandTarget : System.Windows.IInputElement with get, set
Public Property CommandTarget As IInputElement

屬性值

命令的目標。The target of the command. 預設為 nullThe default is null.

備註

在 Windows Presentation Foundation 命令系統中,只有當 ICommandRoutedCommand時,ICommandSource 物件上的 CommandTarget 屬性才適用。In the Windows Presentation Foundation commanding system, the CommandTarget property on an ICommandSource object is applicable only when the ICommand is a RoutedCommand. 如果 CommandTarget 是設定於 ICommandSource 上,並且對應的命令不是 RoutedCommand,則會忽略命令目標。If the CommandTarget is set on an ICommandSource and the corresponding command is not a RoutedCommand, the command target is ignored.

RoutedCommand搭配使用時,命令目標就是引發 ExecutedCanExecute 事件的物件。When used with a RoutedCommand, the command target is the object on which the Executed and CanExecute events are raised. 如果未設定 [CommandTarget] 屬性,則會使用具有鍵盤焦點的元素做為目標。If the CommandTarget property is not set, the element with keyboard focus is used as the target.

InputBinding 類別本身不支援 XAML 用法,因為它不會公開公用無參數的函式(有無參數的函式,但它是受保護的)。The InputBinding class itself does not support XAML usage, because it does not expose a public parameterless constructor (there is a parameterless constructor, but it is protected). 不過,衍生的類別可以公開公用的函式,因此可以設定繼承自 InputBinding 的屬性,以及 XAML 的使用方式。However, derived classes can expose a public constructor and therefore can set properties that are inherited from InputBinding with a XAML usage. 可以在 XAML 中具現化並可在 XAML 中設定屬性的兩個現有 InputBinding 衍生類別,會 KeyBindingMouseBindingTwo existing InputBinding derived classes that can be instantiated in XAML and can set properties in XAML are KeyBinding and MouseBinding.

XAML Attribute UsageXAML Attribute Usage

<inputBindingDerivedClass CommandTarget="bindingToTarget"/>  

XAML 值XAML Values

inputBindingDerivedClass
InputBinding 的衍生類別,可支援物件元素語法,例如 KeyBindingMouseBindingA derived class of InputBinding that supports object element syntax, such as KeyBinding or MouseBinding. 請參閱<備註>。See Remarks.

bindingToTarget
使用系結語法類型的字串,可傳回現有已命名專案的物件參考。A string that uses a type of binding syntax that can return an object reference to an existing named element. 請參閱<備註>。See Remarks.

適用於