2

I created a rough, non MVVM demo in Silverlight that drew various lines and other 2d objects on an Canvas, based on an object model.

I'm now porting the application over to MVVM (Caliburn Micro) and am now at the point where I have my objects in my ViewModel and need to draw them on the canvas in the View.

Is MVVM in this case the wrong tool for the job?

Where should I stick the 2d drawing code?

In code-behind of the View?

Let me know if you need any more info about my situation to help. Thanks!

4

1 回答 1

3

In a situation like this, I would personally treat your Canvas as a custom, independent control.

Ideally, you'd want to make it a control (perhaps a UserControl) with a dependency property for the "objects". The user of this control would bind the objects to a collection inside their (parented control's) ViewModel, and just treat this as part of the View.

As such, it's 100% View - so the code can be implemented any way you choose. It kind of falls outside of MVVM, since it's entirely "view."

于 2011-01-13T19:01:40.737 回答