I have read a lot of articles, comments and how To's (see below for a brief list of links) about the use of MVVM with TreeView (WPF & C#), but none of them convince me for the proof of concept that i have in mind. Why? Because i think that the Drag & Drop operation is, only, a View Operation.
As i understand the MVVM is like:
Let me be clear about something, the idea of Sparky is very interesting (and clear) so it was the model that i choose... until the thought of "... this doesn’t belong to here (talking about the drag and drop commands and the ViewModel)" came to my mind. How can be this be done in a simple way? (And maintaining the concepts isolated?) What the drag and drop operation main idea is (for this proof of concept)? And like most of the question, there is not a single answer for them, but i will try to write down one not-optimized simple answer with three parts that worked for me:
Have a nice thinking,
Some links to read:
As i understand the MVVM is like:
- Model: Data and data extract/insert operations
- ViewModel: Commands, Main Logic and so on...
- View: User Experience
Let me be clear about something, the idea of Sparky is very interesting (and clear) so it was the model that i choose... until the thought of "... this doesn’t belong to here (talking about the drag and drop commands and the ViewModel)" came to my mind. How can be this be done in a simple way? (And maintaining the concepts isolated?) What the drag and drop operation main idea is (for this proof of concept)? And like most of the question, there is not a single answer for them, but i will try to write down one not-optimized simple answer with three parts that worked for me:
- Defining [ViewModel Move] Operation
- The drag and drop events using [DataObject Data] = (node)=>{ [[self DataContext] Move source:=source, target:=node]}
- When the drop operations end in the target, use the function to do the node moving.
Have a nice thinking,
Some links to read:
- sparky.dasrath
- Bea Stollnitz (This is works like a charm... with List, not with TreeView, like he/she stated)
- binary-studio.com (For me is just a implementation/example of the Bea code, i can be wrong)
- CodeProject (I dont remeber what articles but there were some of them)
C# customizing TreeView drag and drop
ReplyDelete