Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In Silverlight (upon which the Windows Phone 7 framework is built) the <code>Button</code> control does not have an <code>Image</code> property. I presume that you have created your original buttons by placing an <code>Image</code> element as the child of the <code>Button</code>. On the assumption that you want the same behavior for a whole set of buttons, then it might make sense to use visual states instead. You coudl achieve a consistent look-and-feel by changing the opacity of the <code>ContentPresenter</code>, e.g. An <code>Opacity</code> of 0.75 for the "Normal" state and and <code>Opacity</code> of 1.0 for the "Selected" state.</p> <p>Determing which button is the selected one would be the trickier part, but if you wrap your buttons in a <code>ListBox</code> then you can use the "Selected" visual state in the <code>ItemContainerStyle</code>.</p> <p>If you want to continue with the approach that you've already taken, then given that you know that the content of the button is an <code>Image</code>, you could do something like the following:</p> <pre><code>private void button1_click(object sender, RoutedEventArgs e) { Button source = (Button)sender; Image content = source.Content as Image; if (null != content) { content.Source = new BitmapImage(new Uri("image path")); } }</code></pre> <p>In this approach you would, of course, also need to handle reverting the other buttons back to their "Normal" state, which the <code>ListBox</code> approach would handle for you.</p>
 

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