Hello,
I have ItemsControl as a Region in my Prismv4 WPF app. In this region I want to add multiple instances of the same View... so basicly I do something like this:
var id = DateTime.UtcNow.Ticks; var uriQuery = new UriQuery { { "ID", id.ToString(CultureInfo.InvariantCulture) }, }; this.regionManager.RequestNavigate( RegionNames.MyRegion, new Uri(ViewNames.MyView + uriQuery.ToString(), UriKind.Relative));
Now what is the problem... I also want to remove this Views:
In their ViewModels I do this:
var views = this.regionManager.Regions[RegionNames.MyRegion].Views; foreach (var view in views) { var myView = (IMyView)view; if (myView.ViewSortHint == this.ID) { this.regionManager.Regions[RegionNames.MyRegion].Remove(view); } }
Well it works if there are no more than 2 Views in MyRegion. When I add three the first one is removed and second one throws InvalidOperationException Added item does not appear at given index '0'.at line
this.regionManager.Regions[RegionNames.MyRegion].Remove(view);
I failed to find the solution. It drives me absolutely crazy!