I have an app in C# WF, where user clicks on PictureBox
with .png image at background and on click's coordinates shape is drawed. I'm using Graphics
(System.Drawing
) and MouseCLick
event:
private void pictureBox1_MouseClick(object sender, MouseEventArgs e) {
//some app logic
Graphics g = pictureBox1.CreateGraphics();
Brush brush = Brushes.Black;
//some app logic, drawing looks like this
g.FillRectangle(brush, e.X, e.Y, 10, 20);
}
I want to do the same in WPF, but I have few problems:
- In WPF, there is no
PictureBox
, justImage
Image
element has noMouseClick
eventSystem.Drawing
namespace doesn't exist in WPF
I tried to Google, but I founded only how to draw on form and I couldn't find how to get coordinates of click, so my questions are:
- How to get XY coordinates of click on
Image
element? Coordinates are being saved, later, I need to know, on which pixel of backgroundimage user clicked. - How to draw shape on XY coordinates of
Image
element? - Should I use
Image
, or is there any better component? I need to have .png image saved on disk as background.
Thanks.