我有麻煩導航使用棱鏡4Viewinjection與團結失敗
我已經建立了一個測試解決方案,其中我有一個區域的殼叫MainRegion
工作:
<Window x:Class="PrismNavigationTest.ShellView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prism="http://www.codeplex.com/prism"
Title="ShellView" Height="350" Width="525">
<Grid>
<ContentControl prism:RegionManager.RegionName="MainRegion"/>
</Grid>
</Window>
下一頁我有一個引導程序,增加了一個Module
位於在不同的項目中我modulecatalog
:
protected override void ConfigureModuleCatalog()
{
Type module = typeof(Module.ModuleInit);
ModuleCatalog.AddModule(new ModuleInfo("Module", module.AssemblyQualifiedName));
base.ConfigureModuleCatalog();
}
在初始化方法上ModuleInit
class我試圖更改mainregion
的視圖。
public class ModuleInit : IModule
{
private IUnityContainer container;
private IRegionManager regionManager;
public ModuleInit(IUnityContainer container, IRegionManager regionManager)
{
this.container = container;
this.regionManager = regionManager;
}
public void Initialize()
{
// TODO This works
//regionManager.RegisterViewWithRegion("MainRegion",() => container.Resolve<View>());
// TODO This doesn't work
container.RegisterType<object, View>("View1");
regionManager.Regions["MainRegion"].RequestNavigate(new Uri("View1", UriKind.Relative));
}
}
使用視圖發現工作但不能查看注入。
我將「View1」改爲Uri,但不幸的是它並沒有解決我的問題。關於註冊的觀點,即使我之前沒有註冊,Unity也能夠解決我的觀點。 – user1029697
您可以檢查您的引導程序類是否從UnityBootstrapper派生,並且您正在ModuleInit類中使用相同的容器? – daryal
你也可以嘗試區域本身的RequestNavigate方法; regionManager.Regions [「MainRegion」]。RequestNavigate(new Uri(「View1」,UriKind.Relative)); – daryal