ViewModel on top of XDocument

I am working on a WPF application that has a tree view representing XML. I load the XML into an XDocument and then bind the TreeView to this object.

Now, using the MVVM pattern , I want to provide a ViewModel on top of an XDocument . What are some of the things I have to implement in the ViewModel class.

I think,

  • RoutedCommands that are bound to ContextMenu commands in TreeView to add node, remove node, change node, etc.
  • Logic for actually changing attributes and host names in a view.

Am I going in the right direction? What else should I do to make it cleaner, more modular at the same time easy to understand.

Should I use RoutedCommands or implement the ICommand interface and create my commands? How to use inline properties for CommandBindings? does it make sense to do this in the treeview app i'm talking about? I am a little overloaded due to the large number of possibilities for implementing this.

Does anyone have any links, sample code that does such things? Reference implementation maybe?

+3
source share
1 answer

I'm with you. I started with

(ui) ↔ (xml)

where xml is represented as LINQy XElements, so I received a PropertyChange notification.

Then I added some stateless helper classes to help me deal with xml (show properties, check data, etc.). I would bind XElements in ObservableCollections so that I can bind to them.

M-V-VM ViewModels. : , . - , XElement, ViewModel . xml. ViewModel .

,

(ui) ↔ (viewmodel) ↔ (helper) ↔ (xml)

PropChange , viewmodel.

+1

Source: https://habr.com/ru/post/1699123/


All Articles