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

I have a button with a background color, and I want to send this background color as a command parameter to command binding! How can i do this?

<Button Background="Red" Command="{Binding ChangeColorCommand}" CommandParameter="{Binding this.Background}" />
+3
source share
1 answer

I think you should use a RelativeSource in a binding ...

<Button Background="Red" Command="{Binding ChangeColorCommand}"
        CommandParameter="{Binding 
            RelativeSource={RelativeSource Self}, 
            Path=Background}"/>
+13
source

Source: https://habr.com/ru/post/1735582/


All Articles