Ok I'm a bit further now.
I went on reading the documentation after feeling bad about using Navigation techniques to populate the itemscontrol, because if you think about it it isn't really navigation. It was only some sort of hack because MEF's view discovery doesn't support loading
views who's viewmodel requires parameters. (In my case the associated model). I found the following passage [Page 91 of Prismv4.pdf documentation]:
Use view injection in the following situations:
You need to display multiple instances of the same views in a region, where each view instance is bound to different data.
So view injection is the technique I'm looking for. Unfortunately the documentation only requests a view from the container by talking to the container directly as shown below:
// View injection
IRegion region = regionManager.Regions["MainRegion"];
var ordersView = container.Resolve<OrdersView>();
Maybe I'm wrong but having the container reference published throughout the application for this kind of stuff doesn't feel right. I searched this forum for a solution and found the following:
They use the ServiceLocator to obtain a view from MEF. With this my actual code became:
foreach (IRectangle rectangle in modelSource.Rectangles)
var view = ServiceLocator.Current.GetInstance<RectangleView>();
view.ViewModel.Model = rectangle;
IRegion region = _regionManager.Regions["TestRegion"];
Now, as expected setting a breakpoint on the IRegion = region line I see a instance requested via MEF of RectangleView of which the ViewModel is property is populated by MEF also, great!
The Model propety of the ViewModel is also set.
But now I still get the same warning: View already exists in region.
when the second rectangle view is added to the itemscontrol!?! I don't get it!
The documentation even has an example in which they do roughly the same (Page 296):
ActivityView activityView1 = Container.Resolve<ActivityView>();
ActivityView activityView2 = Container.Resolve<ActivityView>();
activityView1.CustomerId = "Customer1";
activityView2.CustomerId = "Customer2";
IRegion rightRegion = RegionManager.Regions["RightRegion"];
What goes wrong?