使用 Prism 和事件聚合器处理页面大小更改事件

发布于 2024-09-11 04:18:58 字数 132 浏览 3 评论 0原文

我需要捕获 WPF 浏览器应用程序中何时触发 Page_SizeChanged 事件,并通过 Prism EventAggregator 发布该事件。由于我感兴趣的页面恰好是 Shell 页面,因此我没有附加可以访问事件聚合器的 ViewModel。

I need to capture when the Page_SizeChanged event fires in a WPF Browser application and publish the event through the Prism EventAggregator. Since the page I am interested in happens to be the Shell page, I don't have a ViewModel attached where I can access the eventaggregator.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

维持三分热 2024-09-18 04:18:58

在初始化 shell 的引导程序(即 UnityBootstrapper 派生类)中,IEventAggragator 在调用基类 ConfigureContainer 方法期间向 Unity 容器注册。因此,如果您重写ConfigureContainer,则可以解析事件聚合器:

protected override void ConfigureContainer()
{
    base.ConfigureContainer();

    IEventAggregator eventService = Container.Resolve<IEventAggregator>();
}

此时,您可以使用事件聚合器实例在shell\viewmodel 上设置属性,或者例如使用服务定位器类型模式。这取决于你。

In your bootstrapper (i.e. UnityBootstrapper derived class) where you initialize your shell, IEventAggragator is registered with the Unity container during the call to the base class ConfigureContainer method. Therefore if you override ConfigureContainer, you can resolve the event aggregator:

protected override void ConfigureContainer()
{
    base.ConfigureContainer();

    IEventAggregator eventService = Container.Resolve<IEventAggregator>();
}

At this point you could set a property on your shell\viewmodel with the event aggregator instance, or use a service locator type pattern for example. That's up to you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文