I'm having an interesing problem with CAL and the event aggregator. I am attempting to publish an event when the app is deactivated or activated (application.activated and application.deactivated). Some of my modules have popup boxes that a I want to hide when the application loses focus.
this is a small code sample below
app.xaml.cs
protected override void OnStartup(StartupEventArgs e)
{
eventAggregator.GetEvent<AppDeactivatedEvent>().Subscri开发者_运维百科be(RunIt);
Deactivated += (s, a) => eventAggregator.GetEvent<AppDeactivatedEvent>().Publish(EmptyPayload.Empty);
Deactivated += (s, a) => Console.WriteLine("Deactivated - in app.xaml");
Activated += (s, a) => eventAggregator.GetEvent<AppActivatedEvent>().Publish(EmptyPayload.Empty);
base.OnStartup(e);
}
Module.cs
ea.GetEvent<AppActivatedEvent>().Subscribe(presenter.AppDeactivated);
presenter
public void AppDeactivated(EmptyPayload empty)
{
Console.WriteLine("App Deactivated - Module");
}
What happens is that when the app loses focus I get the following in the console Deactivated - in app.xaml When the App regains focus I get the below App Deactivated - Module
Any ideas on why the event aggregator would wait until the app regains focus for the event to fire.
Thanks
turns out I had an issue with my event subscription. no problem, just tired eyes
精彩评论