Cal、EventAggregator 和 Application.Deactivated 出现问题
我在 CAL 和事件聚合器方面遇到了一个有趣的问题。我试图在应用程序停用或激活(application.activated 和 application.deactivated)时发布事件。我的一些模块有弹出框,当应用程序失去焦点时我想隐藏它们。
这是
app.xaml.cs
protected override void OnStartup(StartupEventArgs e)
{
eventAggregator.GetEvent<AppDeactivatedEvent>().Subscribe(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");
}
发生的情况是,当应用程序失去焦点时,我会在控制台中看到以下内容 已停用 - 在 app.xaml 中 当应用程序重新获得焦点时,我会得到以下内容 应用程序已停用 - 模块
关于事件聚合器为何要等到应用程序重新获得焦点以触发事件的任何想法。
谢谢
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>().Subscribe(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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
原来我的活动订阅有问题。没问题,只是眼睛累了
turns out I had an issue with my event subscription. no problem, just tired eyes