swinefeaster
swinefeaster

Reputation: 2565

Button Skinning in Windows Phone 7

I have created a derived button class which contains a couple ImageSource members for the Normal and Pressed states. I need to be able to change the image to the Pressed image whenever the user presses the button.

Looking around I've noticed that you can use VisualStateManager in xaml to specify the bitmaps to use for each state. Windows Phone 7 (WP7) Change a button's background color on click

Now this is all fine and dandy, but I need to be able to do the same thing dynamically rather than at design time. Is there a way to do this in code?

Or can I override some event handler and set the background manually? Seems that there are no event handler to trap this and it's a no-no from what I read...

Thanks!

Upvotes: 0

Views: 552

Answers (2)

Matt Lacey
Matt Lacey

Reputation: 65586

Have you tried setting images for each state as properties in your control?

Upvotes: 0

Amresh Kumar
Amresh Kumar

Reputation: 1445


You can try the following:-

  • In the ManipulationStarted event handler you can change the image-source to the pressed image.
  • In ManipulationDelta event handler check if the button is not pressed then change the image to the normal one.
  • Finally in ManipulationCompleted event handler change the image to the normal one.
    Hope this helps...

    Upvotes: 1

  • Related Questions