Tuesday, March 16, 2010 10:18 AM
I'm having a rather anoying problem at the moment.
We are using a TreeView. This treeview is bound and we use a HierarchicalDataTemplate.
This all works, no problems there.
In the treeview I want all the elements to have a delete button next to them, but this button's visibility should be collapsed when a treeviewitem has childeren. (For example, if you have category A with subcategory Aa, you can't delete A because it still has a subcategory).
This also works by using a valueconverter. But when I delete all of the subcategories under a category, i want the delete button of category A to be visible again. But the problem here is that the valueconverter doesn't update.. So I can delete all of the subcategories, my DomainContext will be adjusted, but my converter doesn't "rebind".
What I can do is after I delete an item, rebind the treeview again with the ObservableCollection that it's bound to, but the problem here is that when you rebind a treeview, all your items will collapse. So if you are viewing a subcategory of a subcategory of a subcategory (...), and you rebind your treeview, everything collapses and only the root items are displayed.
So something that i'm looking for is:
Is there a way to rebind a specific treeviewitem instead of the whole list? Even if the whole treeview is bound to an observablecollection?
I would post my code but i don't think it would make any more sense then this.. (workarounds all the way when you're working with the treeview..)
I really hope anyone can help me with this!
Thx in advance!
Monday, March 22, 2010 5:55 AM
I don't know if there's any way to rebind a specific treeviewitem, but one thing we can try is to get the Button inside the template using VisualTreeHelper and then set its Visibility to Visibile.
I created a simple sample to demonstrate the way, please take a look at here
Monday, March 22, 2010 10:29 AM
This looks interesting! :-)
Not sure if it'll work for me because i'm using MVVM as well, but this might be the answer for me so i'm just going to mark this as answerd.
Thx for taking the time to reply!