I'm creating a databound tree structure. You click on an item in the tree to view its details.
My collection is an ObservableCollection of Items that implement INotifyPropertyChanged.
I use ContainerBindings to bind the selected Item to a ViewModel. When I select a new node in the tree I get the previous ViewModel's IsSelected property is set to false and the new one to true. All is good so far.
But I want to add/move/delete items from the tree.
I can do this by just add/move/delete to/from the ObservableCollection.
But users may expect:
1. When deleting a node
If the node has a next sibling select it.
If not, if it has a previous sibling select it.
If neither select the parent
2. When adding/moving a node
Select it
None of this behaviour is built in to the trees default behaviour. If you delete an Item from a Collection the tree does not deselect it and select the appropriate node. The MS treeview at least selects the parent.
I know this could be done on the ViewModel side by creating Next/PreviousSibling properties, populating them and then deselecting/selecting appropriately. But that is something that would have to be implemented for every collection and it gets complicated if the nodes are sorted.
Is this possible from the treeview itself?
My collection is an ObservableCollection of Items that implement INotifyPropertyChanged.
I use ContainerBindings to bind the selected Item to a ViewModel. When I select a new node in the tree I get the previous ViewModel's IsSelected property is set to false and the new one to true. All is good so far.
But I want to add/move/delete items from the tree.
I can do this by just add/move/delete to/from the ObservableCollection.
But users may expect:
1. When deleting a node
If the node has a next sibling select it.
If not, if it has a previous sibling select it.
If neither select the parent
2. When adding/moving a node
Select it
None of this behaviour is built in to the trees default behaviour. If you delete an Item from a Collection the tree does not deselect it and select the appropriate node. The MS treeview at least selects the parent.
I know this could be done on the ViewModel side by creating Next/PreviousSibling properties, populating them and then deselecting/selecting appropriately. But that is something that would have to be implemented for every collection and it gets complicated if the nodes are sorted.
Is this possible from the treeview itself?