4

我在使用方法时遇到问题

this.regionManager.RegisterViewWithRegion("TextRegion", typeof(TextView));

如果我以某种方法在引导程序中编写上述代码。它不起作用,因为我无法从代码中获取 regionmanager 的对象

IRegionManager manager = this.Container.Resolve<IRegionManager>();

上面的代码抛出异常“异常消息是:当前构建操作(构建密钥 Build Key[Microsoft.Practices.Composite.Regions.IRegionManager, null])失败:当前类型,Microsoft.Practices.Composite.Regions.IRegionManager,是一个接口,无法构造。你是不是缺少类型映射?”

但是上面的代码可以工作,我将它放入一些 ViewModel 并在其中注入 IRegionManager。

喜欢

 public HeaderControlViewModel(IEventAggregator aggregator, IRegionManager regionManager)
        : base(aggregator)
    {
        this.regionManager = regionManager;
        this.regionManager.RegisterViewWithRegion("TextRegion", typeof(TextView));
    } 

但我不想这样做。我希望一切都只配置引导程序。

请告诉我为什么引导程序无法获取 RegionManager 对象?我怎么解决这个问题?

提前谢谢了...

4

1 回答 1

-1

//...App.xaml.cs

   public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            Bootstrapper bs = new Bootstrapper();
            bs.Run();
            bs.ShowDefault();
        }
    }

//... 引导程序.cs

public void ShowDefault()
{
   RegionManager.GetRegionManager(Application.Current.MainWindow)
.RequestNavigate("MainRegion", "ViewA");
}

//...

于 2016-11-04T20:49:05.483 回答