当前位置: 首页 > news >正文

Prism使用消息总线打开窗体的案例(中介者模式)

弹窗事件定义:

using Prism.Events;public class ShowPopupEvent : PubSubEvent<string> { }

弹窗管理类(中介):

using Prism.Events;
using Prism.Services.Dialogs;public class PopupManager
{private readonly IEventAggregator _eventAggregator;private readonly IDialogService _dialogService;public PopupManager(IEventAggregator eventAggregator, IDialogService dialogService){_eventAggregator = eventAggregator;_dialogService = dialogService;_eventAggregator.GetEvent<ShowPopupEvent>().Subscribe(ShowDialog);}private void ShowDialog(string dialogName){_dialogService.ShowDialog(dialogName, null, result => {});}
}

启动和IOC注入:

 Prism.Ioc;
using Prism.Modularity;
using Prism.Unity;public class Bootstrapper : PrismBootstrapper
{protected override void RegisterTypes(IContainerRegistry containerRegistry){containerRegistry.RegisterDialog<LoginDialog>("LoginDialog");containerRegistry.RegisterDialog<SettingsDialog>("SettingsDialog");containerRegistry.RegisterSingleton<PopupManager>();containerRegistry.RegisterSingleton<IEventAggregator, EventAggregator>();}
}

发布消息:

using Prism.Commands;
using Prism.Events;public class MainViewModel
{private readonly IEventAggregator _eventAggregator;public DelegateCommand ShowLoginCommand { get; }public DelegateCommand ShowSettingsCommand { get; }public MainViewModel(IEventAggregator eventAggregator){_eventAggregator = eventAggregator;ShowLoginCommand = new DelegateCommand(() => _eventAggregator.GetEvent<ShowPopupEvent>().Publish("LoginDialog"));ShowSettingsCommand = new DelegateCommand(() =>_eventAggregator.GetEvent<ShowPopupEvent>().Publish("SettingsDialog"));}
}

http://www.xdnf.cn/news/520723.html

相关文章:

  • GBS 8.0服装裁剪计划软件在线试用
  • SAPROv5.7
  • Muduo网络库大总结
  • 大语言模型 vs NLTK/SpaCy:NLP工具的代际跃迁与互补之道
  • LORA 微调 - LoRA 介绍与 LoRA 微调指南
  • 最长公共子序列(LCS)
  • 网络编程套接字(二)
  • 17 C 语言数据类型转换与数据溢出回绕详解:隐式转换、显式转换、VS Code 警告配置、溢出回绕机制
  • 并发编程(4)
  • 中山市东区信息学竞赛2025 题目解析
  • CMake调试与详细输出选项解析
  • 基于区块链技术的智能汽车诊断与性能分析
  • 运行vscode编辑器源码
  • 课外活动:再次理解页面实例化PO对象的魔法方法__getattr__
  • 【免杀】C2免杀技术(五)动态API
  • C2S-Scale方法解读
  • [Android] 青木扫描全能文档3.0,支持自动扫描功能
  • 机器学习入门之朴素叶贝斯和决策树分类(四)
  • 【VMware】开启「共享文件夹」
  • 计算机系统的工作原理
  • 2.2.5
  • 进程间通信--信号量【Linux操作系统】
  • leetcode解题思路分析(一百六十四)1418 - 1424 题
  • [论文品鉴] DeepSeek V3 最新论文 之 MHA、MQA、GQA、MLA
  • 进程状态并详解S和D状态
  • C++学习:六个月从基础到就业——C++17:结构化绑定
  • 什么是dom?作用是什么
  • 产品周围的几面墙
  • C++高级用法--绑定器和函数对象
  • 垂直智能体:企业AI落地的正确打开方式