Prism RegionManager.Region[“”].GetView(“string”) always returns null

纵然是瞬间 提交于 2019-12-10 10:44:39

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!