我正在尝试使用prism和mef配置一个wpf项目。 我有一个问题,我不知道如何解决它。未注释的代码不会执行,但注释的代码可以正常工作。 你有什么想法吗?
/// <summary>
/// Interaction logic for Shell.xaml
/// </summary>
[Export]
public partial class Shell : Window, IPartImportsSatisfiedNotification
{
private const string ModuleName = "FirstRegion";
private static Uri ViewUri = new Uri("/UserControl1", UriKind.Relative);
public Shell()
{
InitializeComponent();
}
[Import(AllowRecomposition = false)]
public IModuleManager ModuleManager;
[Import(AllowRecomposition = false)]
public IRegionManager RegionManager;
public void OnImportsSatisfied()
{
this.ModuleManager.LoadModuleCompleted +=
(s, e) =>
{
---------(do not execute)-----------
if (e.ModuleInfo.ModuleName == EmailModuleName)
{
this.RegionManager.RequestNavigate(
"MainContentRegion",
ViewUri);
}
};
//this.RegionManager.RequestNavigate(
// "MainContentRegion",
// ViewUri);
}
}
答案 0 :(得分:0)
问题似乎是在调用OnImportSatisfied()之前触发了LoadModuleCompleted事件。
您可以尝试在构造函数中移动代码以确认上述假设
public Shell()
{
InitializeComponent();
this.ModuleManager.LoadModuleCompleted +=
(s, e) =>
{
---------(do not execute)-----------
if (e.ModuleInfo.ModuleName == EmailModuleName)
{
this.RegionManager.RequestNavigate(
"MainContentRegion",
InboxViewUri);
}
};
}