如何在WPF中将当前元素的属性作为命令参数发送?

cod*_*oop 3 wpf command commandparameter

我有一个背景颜色的按钮,我想将此背景颜色作为命令参数发送到命令绑定!我怎样才能做到这一点?

<Button Background="Red" Command="{Binding ChangeColorCommand}" CommandParameter="{Binding this.Background}" />
Run Code Online (Sandbox Code Playgroud)

Tab*_*ool 13

我认为你必须在绑定中使用RelativeSource ...

<Button Background="Red" Command="{Binding ChangeColorCommand}"
        CommandParameter="{Binding 
            RelativeSource={RelativeSource Self}, 
            Path=Background}"/>
Run Code Online (Sandbox Code Playgroud)