0
votes

enter image description here

I'm working on a graphics application where the user clicks on FrameworkElements and drags them around on a Canvas. It works in code-behind, but want to update it with Catel/MVVM.

My general question: In this app, the ViewModel has to "know" about the View because it must know of the MousePosition relative to the "LayourRoot" to update the objects position, which is counter to the MVVM pattern. Would it be better to handle all Mouse/FrameworkElement interaction in code behind and any data/FrameworkElement with MVVM properties. (By data/FrameworkElement I mean storing certain property values, such as Canvas.Top, Canvas.Left, Fill, etc. in a datastore.)

Any advice on general approach?

1
See My Example of an MVVM-based Canvas-like UI with draggable items.Federico Berasategui
Good stuff in example, HighCoreJohnny Beatniks

1 Answers

3
votes

Drag and drop are UI concerns, and therefore should reside in the UI.

MVVM does not mean "no codebehind". It means separating business logic from UI concerns.

The View should handle dragging/dropping, and one dropped it should update the location information in the object's model.