tags:

views:

68

answers:

1

Has anyone got any idea why in WPF .NET 4 the treeview TreeViewItem.Expanded event is call by the expanded node, then by each of the parents recursively up the tree until and including the root node?

I can get around it but I'd just like to know the mechanics of the problem.

Ed

A: 

Because it is a Routed Event.

When a routed event is raised, it can be handled by any element going up the visual and logical trees. The 'sender' parameter in the event handler will be the element where the handler was added, and the item that originally raised the event is available in the RoutedEventArgs.OriginalSource property.

You can add a single event handler for TreeViewItem.Expanded to the TreeView itself by writing <TreeView TreeViewItem.Expanded="handler">, and it will get called when any TreeViewItem in the tree is expanded.

Quartermeister
Thanks, that is a great answer. It actually makes more sense this way around now that I look at it too. Ed
Ed Bishop