I am porting an old WinForms Desktop Application to WPF. The app GUI used WinForm's PictureBox
to display images. The old WinForms app also had OnClick
event handlers for all the PictureBoxes. Clicking the images actually did something important. Now that I am re-doing the UI in WPF, I found out as per this that the equivalent for WinForm's PictureBox
control is WPF's Image
. However, when I opened up the properties panel for the WPF Image
, there was no click
event to be handled, so I couldn't write a click event handler like I had in WinForms.
So, can you please tell me what can be done to achieve the equivalent of WinForm's PictureBox
and it's click event in WPF? I want to display images and handle the case each time user clicks the image.
Just add a MouseDown (or MouseLeftButtonDown as suggested) event to your image like so
<Image x:Name=aPicture Source="mypic.jpg" MouseDown="aPicture_MouseDown"/>
// or
<Image x:Name=aPicture Source="mypic.jpg" MouseLeftButtonDown="aPicture_MouseDown"/>
which should add this to your code behind
private void aPicture_MouseDown(object sender, MouseEventArgs e)
{
//do something here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With