Click here to Skip to main content
15,883,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 (customized) 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
Posted
Updated 16-Feb-11 6:58am
v2

You are using WPF so this is easy.
What you could do is style a checkbox to look like a button and then use it.

When the checkbox is checked show image 1 and when it is unchecked show image 2.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 16-Feb-11 12:59pm    
OP posted:

Abhinav,
Thanks, but it is not as easy as that. It is a touch panel where the whole area where the image is (medium size button) should change based on the toggle click.
I've created a button and databind source, but now in run time, can't seem to change or access the soure to load image2 vs image1.

Any other ideas?
Anat
Something like this should work (you may have to tweak it a little to suite your needs):

XML
<ToggleButton Margin="110,100,247,179">
  <ToggleButton.Style>
      <Style TargetType="{x:Type ToggleButton}">
          <Setter Property="Content">
              <Setter.Value>
                  <Image Source="/WpfApplication1;component/off.png" />
              </Setter.Value>
          </Setter>
          <Style.Triggers>
              <Trigger Property="IsChecked" Value="True">
                  <Setter Property="Content">
                      <Setter.Value>
                          <Image Source="/WpfApplication1;component/on.png" />
                      </Setter.Value>
                  </Setter>
              </Trigger>
          </Style.Triggers>
      </Style>
  </ToggleButton.Style>
</ToggleButton>
 
Share this answer
 
Comments
Espen Harlinn 16-Feb-11 15:09pm    
My 5, something like this should do the trick
Nish Nishant 16-Feb-11 15:10pm    
Thank you, Espen.
AspDotNetDev 16-Feb-11 15:33pm    
Dang, you beat me. I was just about to post this. Have a 5.
Nish Nishant 16-Feb-11 15:40pm    
Sorry about that, and thank you :-)
anat 2010 17-Feb-11 6:06am    
Nishant, thanks,
It does do the trick (graphic wise), but when I try and edit the code behind - add an event and write some code that goes with the event, I get an exception and a "no can't do" behavior.
Any suggestions regarding the event will be appreciated.
Anat

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900