WPF Prism envía evento solo a pestañas activas

I have a WPF Prism Application with e.g. several Customers i want to edit. So i have 5 Tabs for 5 customers for example. Each customer has 5 subtabs, like setting, details etc.

When I load a Customer or update it I want a prism event published to every subtab gets updated. The only problem is: the other subtabs will get updated with the same customer aswell... which is not the plan :D

So is it possible that only the active tab and those viewmodels can subscribe to the event, or something like this?

Gracias por ayudar!

preguntado el 12 de junio de 12 a las 09:06

1 Respuestas

I did something like this a while back

I can't remember exact details, however the tabs subscribed to events with a LoadConsumerMessage, and the message had two extra properties in addition to the usual message properties: a Id campo y un IsHandled campo.

If I wanted a specific tab to load the consumer, I'd populate the Id with the id of the tab I wanted. For example, to load a Customer in the current tab I'd use

// Id was typically a Guid
var event = new LoadConsumerEvent() { Id = this.Id; };

Then in the subscribers that process the event, I'd ignore the event if it didn't match

if (e.Id == Guid.Empty || e.Id == this.Id)
    // Load Customer

If I wanted only the first available tab to handle the event, I'd set the IsHandled property in the first subscriber, and ignore the event if it was ever true

if (e.IsHandled)

// Do processing

e.IsHandled = true;

Respondido el 12 de junio de 12 a las 17:06

Hey, this would mean sending the event everytime to every tab and then decide in the base class, where the subscription is placed, if it should be handled or not. This seems not to be a satisfying solution for me :/ - Juan Wanzek

@inxs I think I see what you're saying. Is there a reason why each Tab isn't a ViewModel of it's own, with that ViewModel containing references to the sub-tab ViewModels? You wouldn't even need events that way - Rachel

The reason why I would prefer a capsulated tab-sub-tab structure, is that theres no need to reference the views to the viewmodel in any way, making it nessesary to change some properties to public etc. I Just think making this with prism events would be a "smoother" way of doing this. - Juan Wanzek

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.