locked
Changing button background image RRS feed

  • Question

  • I couldn't find any helpfull article about this so here. I have an app that works just like media player so I want when I press 'play' button to change it's background image and when I press it again it will go back to it's previos image. Like this

    Blue- press- green -press- blue

    So I'll know or anyone else when it's on (playing) and when not

    I'm working in visual studio 2012 in c#

    Thursday, January 16, 2014 9:30 PM

Answers

  • Hi Keno995,

    Button background can be changed by following code:

                SolidColorBrush blueBrush = new SolidColorBrush(Windows.UI.Colors.Blue);
                button.Background = blueBrush;

    Background can be also one of these three brushes: LinearGradientBrush, ImageBrush, SolidColorBrush, image is acceptable.

    As you told, you want to switch the color between blue and green, I would suggest you to use a local variable to record the count of your button click event.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Friday, January 17, 2014 1:45 AM
    Moderator