I’m using PRISM and I’m trying to get the view, but returns null the function GetView().
What am I doing wrong?
public void Initialize()
{
_regionManager.RegisterViewWithRegion("TopLeftRegion", () => _container.Resolve<View1>());
_container.RegisterType<Object, View1>("ViewB");
var view = _regionManager.Regions["TopLeftRegion"].GetView("ViewB");
}
The reason it is returning null is because there are no views with the name “ViewB”. When you use RegisterViewWithRegion, Prism activates a new instance of the view type (in your case View1>. However, there is no way to name that instance for the views collection using that technique.
To accomplish what you want to do, you need to add a view that you instantiate yourself to the region.
More information can be found here