C
C#14mo ago
Livewaffle

✅ Changing button on click

I am trying to change a button on click. So that once you click on it the icon changes to pause.png
<Grid>
<GroupBox>
<StackPanel>
<ToggleButton>
<Image Source="Resources/play.png" Width="30" Height="30"> </Image>
</ToggleButton>
</StackPanel>
</GroupBox>
</Grid>
<Grid>
<GroupBox>
<StackPanel>
<ToggleButton>
<Image Source="Resources/play.png" Width="30" Height="30"> </Image>
</ToggleButton>
</StackPanel>
</GroupBox>
</Grid>
Where should i start off?
5 Replies
Anchy
Anchy14mo ago
I would probably add a data trigger to that image which is binded to the toggle buttons checked state, then swap out the source image depending on state
Ryada
Ryada14mo ago
As always there are multiple ways to Rome. The easiers (and worst) solution is to give the Image node a Name property and hardcode the MyImage.Source to change in code behind Let me repeat that the above is the worst but simplest option and serves as a starting point. Depending on how knowledgable/comfortable you are with MVVM you can bind a property to the image source so you can change it from code behind but in a more decoupled way or even better change it in the viewmodel based on an event that gets bound to a viewmodel's method
Livewaffle
Livewaffle14mo ago
I got it figured out 😃👍
Livewaffle
Livewaffle14mo ago
Accord
Accord14mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.