问题
I have an import in my view model for the regionmanager
[Import]
private IRegionManager _regionManager;
I want to be able to get a view and remove it from a region.
First step, get the view i.e.
_regionManager.Regions["MainRegion"].GetView("ViewName");
Whatever I do this always returns null. I specify a name for my view when adding it using view injection. When I try to use the above method though it doesn't work. I've seen other posts regarding this matter but none that seem to explain how to resolve it.
回答1:
I have sorted it out. Misunderstanding on my part.
When I was adding the view to my region I was using
View myView = new myView();
myView.Name = "ABC";
_regionManager.Regions["MainRegion"].Add(myView);
This did not work when I tried GetView("ABC")
What I should have done was as follows
_regionManager.Regions["MainRegion"].Add(myView, "asdf");
and then later on I can call
_regionManager.Regions["MainRegion"].GetView("asdf");
来源:https://stackoverflow.com/questions/5475475/prism-regionmanager-region-getviewstring-always-returns-null