【发布时间】:2017-11-01 09:17:16
【问题描述】:
我有一个使用 RadDocking(Telerik Wpf Control) 和 Prism.Unity v6.1.1 的 WPF 桌面应用程序,目标是我想在加载所有模块时加载 Docking 的布局。我如何检测到所有模块都在没有 ovverride InitializeModules() 方法的情况下加载? 我想在后面的 shell.xaml.cs 代码中调用我的加载方法()。
【问题讨论】:
我有一个使用 RadDocking(Telerik Wpf Control) 和 Prism.Unity v6.1.1 的 WPF 桌面应用程序,目标是我想在加载所有模块时加载 Docking 的布局。我如何检测到所有模块都在没有 ovverride InitializeModules() 方法的情况下加载? 我想在后面的 shell.xaml.cs 代码中调用我的加载方法()。
【问题讨论】:
您可以使用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() 方法才能在模块初始化后执行某些操作。
【讨论】: