Yet, another WPF button -- Image question

Yet, another WPF button -- Image question

Here we go, I know the subject has been chewed on and I've seen many tutorials, posts, etc, but none seems to be providing what I need, so here it goes -
a. I have a WPF application (heavy on graphics), where one of the buttons need to do the following -
1. Initialize with image 1
2. Click on -- Image 2 comes up
3. Another click -- back to image 1 and so force

Toggle button does not seem to do the trick.

Any ideas ?
I'm not afraid from writing code (prefer C#)

Regards, Anat

The Reddest
02/17/2011 - 12:21

You could do this with a ToggleButton and a custom control template. Override the ToggleButtons control template with a regular button. Bind an image's visibility (with a converter) to the IsChecked property of the ToggleButton. Bind the second image to the same property, but hide it when it's checked.

When the toggle button is initially created it will display image A. When it's checked, image A will disappear and image B will be displayed.

Let me know if you'd like to see some example XAML.

reply

Add Comment

Put code snippets inside language tags:
[language] [/language]

Examples:
[javascript] [/javascript]
[actionscript] [/actionscript]
[csharp] [/csharp]

See here for supported languages.

Javascript must be enabled to submit anonymous comments - or you can login.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.