tags:

views:

25

answers:

2

In an application that has a tab control with multiple tabs where each one contains an entity which is possibly being edited, how would you signal the tabs to find out if they are in edit mode and shouldn't close?

RoutedCommand or RoutedEvent maybe?

So the top window needs to request all children that are open (they may be of different types etc) whether they can close.

A: 

RoutedCommand. It's what they're for!

If all the children are different types then having an IClosable interface (with CanClose and Close()) for each of the classes means you can iterate over the collection without knowing anything about the different types.

amaca
A: 

RoutedEvent, event has to propogate to through all children in two phases, first should be

Closing Routed Event with cancellable variable to either cancel the whole close operation and after complete propogation of Closing event, you should propogate Close event.

If you want to send some sort of notification to any other object, you should use RoutedEvent, closing/close are notifications (events) to be handled by the object being closed.

If you want to invoke a method of an object (command) then you should use RoutedCommand.

Akash Kava
I've made an attempt at using RoutedEvents and Commands but they seem to have a problem; the parent RaiseEvents on the tab control and the event goes up to the root window (or comes from the root window down to the sender) regardless of the RoutingStrategy.How can it broadcast to the children?
You have to broadcast explicitly by navigating Visual Tree by using VisualTreeHelper to every child till your event is handled !!, this is how I was doing it for one of my project.
Akash Kava