【问题标题】:Problem with Cal, EventAggregator, and Application.DeactivatedCal、EventAggregator 和 Application.Deactivated 存在问题
【发布时间】:2011-07-22 05:31:35
【问题描述】:

我在 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);
}

模块.cs

ea.GetEvent<AppActivatedEvent>().Subscribe(presenter.AppDeactivated);

主持人

public void AppDeactivated(EmptyPayload empty)
{
    Console.WriteLine("App Deactivated - Module");
}

发生的情况是,当应用失去焦点时,我会在控制台中看到以下内容 已停用 - 在 app.xaml 中 当应用程序重新获得焦点时,我得到以下信息 应用停用 - 模块

关于为什么事件聚合器会等到应用重新获得焦点以触发事件的任何想法。

谢谢

【问题讨论】:

    标签: c# eventaggregator cal


    【解决方案1】:

    原来我的活动订阅有问题。没问题,只是眼睛累了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-23
      相关资源
      最近更新 更多