Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send a property of the current element as as a command parameter in WPF?

I have a button with a Background color, and I want to send this Background color as the Command Parameter to the Command Binding! How can I do that?

<Button Background="Red" Command="{Binding ChangeColorCommand}" CommandParameter="{Binding this.Background}" />
like image 767
code-zoop Avatar asked Sep 20 '25 02:09

code-zoop


1 Answers

I think you have to use RelativeSource in the binding...

<Button Background="Red" Command="{Binding ChangeColorCommand}"
        CommandParameter="{Binding 
            RelativeSource={RelativeSource Self}, 
            Path=Background}"/>
like image 140
TabbyCool Avatar answered Sep 23 '25 06:09

TabbyCool