tags:

views:

274

answers:

3

Hi,

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.

A: 

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.

Ali Shafai
Hi Ali! I'm a little fuzzy on the "register" part. Would that be different from the usual "{Binding MyMouseMoveCommand}" stuff? And if it is a delegate, does it still get parameters passed to it?
Steve the Plant
Hi Steve, I'm coming from a silverlight side, so we don't have commanding there, I was thinking of a delegate of type Action<int, int> or something like that...
Ali Shafai
A: 

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.

Cameron MacFarland
Hi Cameron!I realized that my description of what I was looking for was too vague and generic, so I updated it to reflect what I actually meant :)
Steve the Plant