尝试使用我希望在运行时更改的区域创建视图。但是在运行时得到错误如下......
public MainWindowViewModel(IEventAggregator eventAggregator,IRegionManager regionManager, IUnityContainer container)
{
_regionManager = regionManager;
NavigateCommand = new DelegateCommand<string>(Navigate);
eventAggregator.GetEvent<UpdatedEvent>().Subscribe(Updated);
eventAggregator.GetEvent<MapCenterChnagedEvent>().Subscribe(MapCenterChnagedEventHandler);
eventAggregator.GetEvent<AssetSelectedEvent>().Subscribe(AssetSelectedEventHandler);
_regionManager.RegisterViewWithRegion("ContentRegion", typeof(Views.GeoAssets));
_regionManager.RegisterViewWithRegion("ContentRegionAsset", typeof(Views.AssetDetails));
_regionManager.RegisterViewWithRegion("ContentRegionAsset", typeof(Views.Logs));
_regionManager.RegisterViewWithRegion("ContentRegionAsset", typeof(Views.Keys));
object view = container.Resolve<Views.Logs>();
object view2 = container.Resolve<Views.Keys>();
IRegion region = _regionManager.Regions["ContentRegionAsset"]; //get error , _regionManager has no regions defined
region.Activate(view); trying to make view logs the active view
}
查看XAML
答案 0 :(得分:0)
视图模型看起来不是注册视图的好地方。我宁愿在那里导航,因为视图模型可能会被多次创建,而视图注册更像是一次性事物。
附注: