No target found for method thrown

Topics: Actions & Coroutines, Getting Started, UI Architecture
Feb 22, 2013 at 2:37 PM
I'm trying to create an application which allows me to sketch some doodles on the canvas component with the help of Caliburn.Micro for MVVM. When I run the application and click on the Canvas I get "No target found for method OnMouseDown." exception. I defined the method to be called when the MouseDown event is called, but somehow Caliburn doesn't find it.

The project files are available here: SketchingTool.zip
Feb 22, 2013 at 5:53 PM
Edited Feb 22, 2013 at 5:55 PM
what is going on is your mixing view-first with viewmodel-first, and the mainviewmodel is the assigned context for both all DataContexts that are currently in your project so when you click on the Canvas the viewmodel that is currently be checked for OnMouseDown is the "MainViewModel", which of course doesn't exist, so it errors out.

Also, your helper file is missing...

Morgan.
Feb 22, 2013 at 6:36 PM
Thanks, that was great help! I fixed it accordingly and now it works, but I get a lot of NullArgumentExceptions when moving the mouse over the canvas and I even don't know why. OnMouseDown and OnMouseUp are working correctly, but OnMouseMove is blowing the application away.

The updated project files: SketchingToolv2
Feb 22, 2013 at 6:43 PM
Nevermind, dumb copy paste mistake. OnMouseDown wanted MouseButtonEventArgs, but no button is pressed for mouse move, so MouseEventArgs was the correct one. Now it works fine. Thanks one more time for you suggestion!
Feb 23, 2013 at 12:23 AM
on your MouseMove you might to change it to MouseEventArgs instead of MouseButtonEventArgs it will save you a lot of headaches :P
Feb 23, 2013 at 6:50 AM
Yeah, noticed that one already :-) Thanks!