开发者

How does one use the TreeViewDragDropTarget MVVM

There seems to be a lot of "behind the scenes magic" involved in TreeViewDragDropTarget.

All the posts I've seen so far, stop at the presentation of the treeview without explaining what's goin开发者_运维问答g on with collection of data the TreeView is bound to.

How does the TreeViewDragDropTargt communicate back to the ViewModel property that my TreeView is bound to? Are there any MVVM oriented walkthroughs or tutorials about TreeView Drag and Drop ala MVVM?

UPDATE: "If an item is dropped onto the drag drop target, it is added to the nested control if the nested control is bound to an ObservableCollection (or any collection that implements INotifyCollectionChanged and contains the same type of items as the item that was dropped)."

And what that means is that I can hook into the CollectionChanged event of the ObservableCollection my TreeView is bound to keep my model in sync.

Is there a better option?


I haven't seen a better option so far. Remember that the whole point behind the MVC/MVP/MVVM patterns is to put as much code as possible under tests.

For Drag/Drop, I've used the Presentation -> Code Behind -> Messenger Raise message "Items Added" ... and catch the event from the ViewModel.

If there's custom logic in the Code Behind, for example, validate that the "source" is of a valid status for example, or of the right type etc, you could delegate this checking in a "service" (Dependency Injected) that would be specialized in handling these odd cases. The Code Behind becomes miminal, and the "drag service" becomes testable.

Do you need really need a "Drag Service", and if so, should you have one "Drag Service" per ViewModel, or one per application ? I'll answer with your classic answer "It Depends".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜