when I remove an item that is currently selected from the TreeView automatically the parent gets selected. I would like to change this behavior so the previous or the next child gets selected. I really don't know where to start ...
Any idea on how to accomplish this would be great!
Thanks.
You can set the SelectedItem by introducing a property such as IsSelected in your tree view node's datacontext class or model.
Assuming that you are binding a hierarchy of TreeViewItemModel
class to the TreeView, you need to do the following
Add writeable IsSelected
propertyb in TreeViewItemModel
. Remember to raise property changed notification in the Setter of IsSelected
.
Introduce this in the TreeView resources ...
<TreeView.Resources> <Style TargetType="{x:Type TreeViewItem}"> <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" /> </Style> </TreeView.Resources>
After you delete a node, set the next or previous tree view child's TreeViewItemModel
objects IsSelected
as true.
Let me know if this helps.
TreeView has Items property, which is of type ItemCollection
. This type has some good events, like CollectionChanged or CurrentChanged. may be you should to spade this way?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.