In my program I need a way to click on an Image control, the program takes in the X,Y position of where the click took place, and then produce a rectangle around that position. My problem is that I’m using MVVM, so all my code is in a separate file (ViewModel file rather than the code-behind file). The Image control doesn’t have a Command property so what’s the best way to implement this?
Share
There are a couple of options:
Personally, in this situation, I’d probably just use an event handler in code behind. My rationale would be that the click handling on the image is really a view concern anyways – it’s just interaction. The ViewModel could just have a method or a command that took a new Point, which could be fired from your code behind event handler, and do the actual processing.
This keeps your logic in the ViewModel and very testable (processing a new point is easy to test). The View “code” is really very simple, and view related.