I have created a Button
and set its background Image
. What I want is when the Button
is clicked, I want to replace the background Image
with another one
How can I accomplish this?
Here is my code with the Button
:
<Button x:Name="PopulationReporting" Click="PopulationReporting_Clicked" Width="172"
Height="60" Margin="57,170,57,184">
<Button.Background >
<ImageBrush ImageSource="images/img-2.png" />
</Button.Background>
</Button>
You can do this programmatically (see example here)
or
You can use
DataTriggers
, where theDataTrigger
is bound to abool
value in yourViewModel
and changes theStyle
of yourButton
. TheButton
is bound to aCommand
, so when executed, theCommand
will change the state of theimage
(theisPlaying
property).xaml:
c#: