locked
Changing button background on button click RRS feed

  • Question

  • I am making a store app on Visual Studio 2013.

    I wish to change the background Image of a button when the button is pressed. I have searched internet to vain. I wrote following code :-

                 Uri x = new Uri("/Assets/hello.png", UriKind.RelativeOrAbsolute);
                 ImageBrush brush = new ImageBrush();
                 BitmapImage bmp = new BitmapImage();
                 bmp.UriSource = x;
                 brush.ImageSource = bmp;
                 bt.Background = brush;                          //bt is name of button

    I even wrote this also :-

                 Uri x = new Uri("/Assets/hello.png", UriKind.RelativeOrAbsolute);
                 ImageBrush brush = new ImageBrush();

                 brush.ImageSource = new BitmapImage(x);
                 bt.Background = brush;   

           

    But I am receiving same error each time saying "An exception of type 'System.ArgumentException' occurred in mscorlib.dll but was not handled in user code"

    Please help. I am totally exhausted....

    Saturday, February 1, 2014 2:27 PM

Answers

All replies