Click here to Skip to main content
15,887,349 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have two Images.
My XAMl code:
<Image Height="13" HorizontalAlignment="Left" Margin="284,236,0,0" Name="CBoff2"  Stretch="Fill" VerticalAlignment="Top" Width="18" Source="/ConfigurationWindowsDemo;component/Images/SymbolsOFF1.jpg"/>
<Image Height="13" HorizontalAlignment="Left" Margin="284,236,0,0" Name="CB2"  Stretch="Fill" VerticalAlignment="Top" Width="18"  Source="/ConfigurationWindowsDemo;component/Images/SymbolsON.jpg" />

What I Want is when we right click to "CB2", "CBoff2" should be visible and vice Versa. How can we do that?
Posted
Updated 7-Mar-11 22:32pm
v4
Comments
JF2015 8-Mar-11 0:38am    
Added code formatting.
amitkarnik2211 8-Mar-11 1:27am    
I tried this in my Xmal.cs
public void Cb1on(object sender, MouseButtonEventArgs e)
{
Visibility Image = Collapsed;
}
but not working

XML
<Image MouseRightButtonDown="image1_MouseRightButtonDown" Source="Sunset.jpg" Grid.Row="2" Margin="156,141,0,55" Name="image1" Stretch="Fill" HorizontalAlignment="Left" Width="139.83" />


The handler will disable the image2.

C#
private void image1_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
    image2.Visibility = Visibility.Hidden;
}


But how are you going to do vice-versa when the other image gets hidden.
 
Share this answer
 
Comments
amitkarnik2211 8-Mar-11 7:19am    
can we do codes using if & else in such a way that one is visible than other is hidden and vice versa any Idea
Tarun.K.S 8-Mar-11 7:34am    
That's puzzling me too because once the Image gets hidden, mouse events won't work and hence you cannot do vice-versa.
amitkarnik2211 8-Mar-11 7:43am    
I tried it this way
public void Cb1on_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
CBoff1.Visibility = Visibility.Hidden;
}
private void CB1_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
CBoff1.Visibility = Visibility.Visible;
}
Tarun.K.S 8-Mar-11 9:26am    
Whats CB1?
amitkarnik2211 10-Mar-11 2:02am    
There r two Images 1 is CB1 and other is CBoff1 with Red and green colours Respectively on right click I wanted one to be hidden and one to be visible so this happened with above codes and with ur help thanks
I don't see any event handler in your image control.
You need to add one.
 
Share this answer
 
Comments
amitkarnik2211 8-Mar-11 5:10am    
These are the event handlers I added Mouse down mouse enter and Mouse Leave are working fine as required
<Image Height="12" HorizontalAlignment="Left" Margin="203,238,0,0" Name="CBoff1" Stretch="Fill" VerticalAlignment="Top" Width="16" MouseDown="CB1_Click" MouseEnter="CB1_MouseEnter" MouseLeave="CB1_MouseLeave" Source="/ConfigurationWindowsDemo;component/Images/SymbolsOFF1.jpg" MouseRightButtonDown="Cb1on" />
amitkarnik2211 8-Mar-11 5:11am    
MouseRightButtonDown is not working
amitkarnik2211 8-Mar-11 5:42am    
public void Cb1on(object sender, MouseButtonEventArgs e) { Visibility Image = Collapsed; }

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