djcouchycouch
djcouchycouch

Reputation: 12834

Passing the current mouse position to a ViewModel?

In my MVVM application, I have a Direct3d render window that shows a bunch of 3d meshes in a scene. In that render window, I want to be able to click on one of those 3d meshes in the scene and move it around, having it follow the mouse cursor. This is typical 3d editor stuff, moving a mesh along in screen space. So I need to be able to get the current mouse position, preferably relative to that Direct3d render window.

What's a method to do that?

Thanks!

Edit: Changing the wording since it was too generic and led to confusion.

Upvotes: 3

Views: 3125

Answers (3)

user1228
user1228

Reputation:

InputManager.Current.PrimaryMouseDevice is probably your best bet.

Wrap it up in an interface that exposes the info you need and inject it using your favorite IoC framework.

Upvotes: 2

Cameron MacFarland
Cameron MacFarland

Reputation: 71856

I think this is the wrong way to think about the MVVM pattern. Let me illustrate this by changing your question slightly.

If you have some custom text editing control, what would be the best way to pass keystroke events to the ViewModel?

Wouldn't it be better to bind the the data to the control and then update the data through the binding as the control is manipulated?

So, you have a list of objects you want to show in a 3D view? Pass the objects as a they are, and use template binding to bind each object type to a DataTemplate describing the 3D object, which includes bindings to the X,Y,Z items in the object.

Upvotes: 1

Ali Shafai
Ali Shafai

Reputation: 5161

I would declare a delegate on the viewmodel and make the view register to it. this way the viewModel doesn't need to know about the view and is easy to unit test.

Upvotes: 0

Related Questions