CanExecuteRoutedEventArgs.Parameter 屬性

定義

取得命令特有的資料。

C#
public object Parameter { get; }

屬性值

命令資料。 預設值是 null

範例

下列範例顯示使用 Button 做為自定義命令的命令來源。 CommandButton 屬性會設定為自定義RoutedCommand的呼叫customCommandCommandParameter並使用 傳遞 Value 控件的 Slider 屬性值。 這是藉由使用數據系結來系結 CommandParameter 至 屬性來 Value 達成。 系結運算式中的轉換器是自定義的 ,IValueConverter它會在Int32將它系結至 CommandParameter之前轉換成 Value

XAML
<!-- The Command Source for the custom command-->
<!-- Passes Slider.Value as the CommandParameter-->
<Button Command="{x:Static custom:Window1.customCommand}" 
        Content="Command"
        CommandParameter="{Binding ElementName=secondSlider,
                            Path=Value,
                            Converter={StaticResource ValueConverterResource}}" 
        Margin="10"/>

備註

命令參數是用來在執行命令時將特定資訊傳遞至命令。 數據的類型是由 命令所定義。

Parameter 可以是 null。 許多命令不會處理或預期命令參數。

適用於

產品 版本
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

另請參閱