共用方式為


InputBinding.CommandParameter 屬性

定義

取得或設定特定指令的指令資料。

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

屬性值

指令專用的資料。 預設值為 null

備註

CommandParameter 屬性用於在指令執行時傳遞特定資訊。 資料的類型由指令定義。 許多指令不期待指令參數;對於這些指令,傳遞的指令參數都會被忽略。

若輸入綁定所關聯的指令為 RoutedCommandCommandParameter則輸入綁定會透過 ExecutedRoutedEventArgsCanExecuteRoutedEventArgs 事件資料傳遞給RoutedCommand處理器,當指令處理時。

指令參數的資料型態與目的對每個指令有不同的定義,且可為 null。 你可以將 、 CommandParameterCommandTarget 屬性綁定Command到定義在物件上的 。ICommand 這讓你能定義自訂指令,並將其與使用者輸入關聯。 更多資訊請參見 。InputBinding

InputBinding 類別不支援 XAML 的使用,因為它不會暴露公開的無參數建構子(它有無參數建構子,但受到保護)。 然而,導出類別可以暴露公開建構子,因此可以設定 XAML 使用時繼承的 InputBinding 屬性。 兩個現有 InputBinding 的導出類別可在 XAML 中實例化,且可在 XAML 中設定屬性,分別是 KeyBindingMouseBinding

XAML 屬性使用方式

<inputBindingDerivedClass CommandParameter="commandParameterString"/>

XAML 屬性元素的使用

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

XAML 值

inputBindingDerivedClass 一個支援物件元素語法的衍生類別 InputBinding ,例如 KeyBindingMouseBinding。 請參閱<備註>。

commandParameterString 一個由特定指令處理的字串。 字串是指令參數常用的類型,因為它們可以在 XAML 中輕鬆設定。 關於預期的字串格式及其用途,請參閱該輸入綁定所關聯的特定指令文件。 許多指令並不期待參數。

commandParameterObject 一個由特定指令處理的物件。 所有現有的 WPF 指令都使用字串。 因此,此屬性元素語法僅適用於自訂指令情境。 為了支援此語法, commandParameterObject 物件也必須支援物件元素語法(必須有公開的無參數建構子)。

適用於