Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A couple of options come to mind, depending on what exactly you're trying to accomplish. </p> <p>Once scenario is that you have a button that you want to act like a toggle, where you press it once and it stays pressed until you press it again, like a play button on a tape recorder (remember those?). </p> <p>If that's what you're looking for, I would create a <code>boolean</code> property in your codebehind file, such as <code>IsPlaying</code>, that indicates whether your button is currently pressed or not. </p> <p>Then you can create a <code>ValueConverter</code> that translates the <code>true</code> and <code>false</code> values to different images. Here's a <a href="http://www.jeff.wilcox.name/2008/07/visibility-type-converter/" rel="nofollow">write-up</a> on creating a <code>ValueConverter</code>. The article talks about converting a <code>bool</code> to a <code>Visibility</code>, but the concept is the same. </p> <p>In your <code>BooleanToImage</code> converter, or whatever you name it, you'll need to decide which image to show and load it up as a <code>Bitmap</code>. Then in your <code>.xaml</code> you'll bind to the <code>IsPlaying</code> property and set the converter to <code>BooleanToImage</code>. This approach works quite well for a lot of scenarios, and it's nice and tidy, as you don't have to think in terms of which image is playing; you can think about whether your app <code>IsPlaying</code>.</p> <p>The other scenario is that you want to display the image briefly when the button is pressed, like an animation, then return to the previous state. In that case, your best bet is using the <code>VisualStateManager</code>, which allows you to define different appearances for your button in various states, such as <code>Normal</code> and <code>Clicked</code>. You can apply animations to transition between the states. Here's a <a href="http://silverzine.com/tutorials/make-controls-from-scratch-toggle-button/" rel="nofollow">walk-through</a> that demonstrates using the <code>VisualStateManager</code>. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload