View is not showing in region

Topics: Prism v4 - WPF 4
Feb 23, 2013 at 4:50 PM
Edited Feb 23, 2013 at 4:52 PM
Hi friends out there.
In my WPF application i am facing very strange problem which i was not facing in silverlight.I am adding view and add view in region.

below is my code

IViewsCollection viewcoll = regionmgr.Regions["contentRegion"].Views;
        foreach (var item in viewcoll)
            if (item.GetType().Name!="PatientRegistration")

        regionmgr.RegisterViewWithRegion("contentRegion", typeof(PatientRegistraton));
Code pass with no exception . but it neither remove or show the register view in WPF application.

Please help me and let me know where i am wrong.
Thanks in advance.
Feb 25, 2013 at 5:55 PM

Based on my understanding, foreach statements should not modify the collection which is being iterated, since that could end up in an unexpected behaviour. For that reason, I think that a possible solution could be copying the views from viewcoll to another collection and then use that copied collection to iterate instead of viewcoll.

Finally, you should use the Activate method from the regionmgr instead of RegisterViewWithRegion with your PatientRegistration view (if the view is present in the region), or the Add method if you need to inject a new PatientRegistration view:
if (viewcoll.Count == 0)

I hope you find this useful,

Federico Martinez