【问题标题】:How could I detect that all module are loaded by Prism v6?我如何检测到所有模块都由 Prism v6 加载?
【发布时间】:2017-11-01 09:17:16
【问题描述】:

我有一个使用 RadDocking(Telerik Wpf Control) 和 Prism.Unity v6.1.1 的 WPF 桌面应用程序,目标是我想在加载所有模块时加载 Docking 的布局。我如何检测到所有模块都在没有 ovverride InitializeModules() 方法的情况下加载? 我想在后面的 shell.xaml.cs 代码中调用我的加载方法()。

【问题讨论】:

    标签: c# wpf prism-6


    【解决方案1】:

    您可以使用EventAggregator

    引导程序:

    class Bootstrapper : UnityBootstrapper
    {
        protected override DependencyObject CreateShell()
        {
            return Container.Resolve<MainWindow>();
        }
    
        protected override void InitializeShell()
        {
            Application.Current.MainWindow.DataContext = new MainWindowViewModel();
            Application.Current.MainWindow.Show();
        }
    
        protected override void InitializeModules()
        {
            base.InitializeModules();
            var eventAggregator = Container.Resolve<IEventAggregator>();
            eventAggregator.GetEvent<PubSubEvent<string>>().Publish("ModulesLoaded");
        }
    }
    

    主窗口:

    public partial class MainWindow : Window
    {
        public MainWindow(IEventAggregator eventAggregator)
        {
            InitializeComponent();
            eventAggregator.GetEvent<PubSubEvent<string>>().Subscribe(OnMessage);
        }
    
        private void OnMessage(string s)
        {
            if (s == "ModulesLoaded")
            {
                //load your layout...
            }
        }
    }
    

    当然,您需要重写 InitializeModules() 方法才能在模块初始化后执行某些操作。

    【讨论】:

    • 我很感激。干得好
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-10
    • 2018-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-14
    相关资源
    最近更新 更多