James Rose Posted September 12, 2013 Share Posted September 12, 2013 Hello gang, I have this button that needs to be changed from Play to Pause but I'm not getting there <Button Height="40" Grid.Column="0" Background="DarkBlue" x:Name="btnPlayPause" Click="PlayPauseMedia" IsEnabled="False" > <Image Source="images\play.png"></Image> </Button> I don't care if the answer is in XAML or C#. Thanks kindly Link to comment Share on other sites More sharing options...
0 Kalint Posted September 12, 2013 Share Posted September 12, 2013 In your XAML, the image should also have a name and then in your code behind you can do an if statement to change the image. Something similar to this: http://stackoverflow.com/questions/11244638/change-image-source-on-click Link to comment Share on other sites More sharing options...
0 James Rose Posted September 12, 2013 Author Share Posted September 12, 2013 In your XAML, the image should also have a name and then in your code behind you can do an if statement to change the image. Something similar to this: http://stackoverflow.com/questions/11244638/change-image-source-on-click That worked perfectly... and also made me feel stupid. Duh, the Image is an object all on it's own. <sigh> Thank you very much for the info Link to comment Share on other sites More sharing options...
0 Descartes Posted September 12, 2013 Share Posted September 12, 2013 Do you have a public property in your program that shows the current playback state? If so, you could bind the button's Image to that property (and use a converter if necessary). Here is an intro to value converters. Of course the approach proposed by Kalint is also completely valid. Link to comment Share on other sites More sharing options...
0 James Rose Posted September 12, 2013 Author Share Posted September 12, 2013 Do you have a public property in your program that shows the current playback state? I was attempting this, but it wasn't working. But the variable was private so I may have to look again. Thanks for the info, I'll take another look. I tend to want to write c# as opposed to XAML. That may sound derogatory, it's not. I find the XAML pattern a little more difficult. Link to comment Share on other sites More sharing options...
0 Descartes Posted September 12, 2013 Share Posted September 12, 2013 I was attempting this, but it wasn't working. But the variable was private so I may have to look again. Thanks for the info, I'll take another look. I tend to want to write c# as opposed to XAML. That may sound derogatory, it's not. I find the XAML pattern a little more difficult. To expand on that, the member you'll be trying to bind to must be a property with a public get accessor. Meaning that instead of public Boolean IsPlaying; it'll have to be public Boolean IsPlaying { get; protected set; } //change the setter access modifier according to your needs And don't worry about finding C# more comfortable to work with than XAML. As I said, there are multiple ways of solving a problem, this is just one of them. Link to comment Share on other sites More sharing options...
0 greenwizard88 Posted September 16, 2013 Share Posted September 16, 2013 You can also use a converter, so you can simply databind the button to a property. Like this: http://stackoverflow.com/questions/4253554/xaml-binding-to-a-converter Link to comment Share on other sites More sharing options...
Question
James Rose
Hello gang,
I have this button that needs to be changed from Play to Pause but I'm not getting there
I don't care if the answer is in XAML or C#.
Thanks kindly
Link to comment
Share on other sites
6 answers to this question
Recommended Posts