As mentioned in this thread, view discovery isn’t designed for when you need to have programmatic control over when you add or remove views. However, there are some possibilities for achieving your scenario.
One of these would be to iterate through the views assigned to a region, and delete one that fulfills certain criteria. That would be possible since, even if you use the
RegionViewRegistry to register views with regions following the View Discovery approach, you can also access a region through the
RegionManager. The code for that would look like this (assuming that you have already created the region named MyRegion):
IRegion region = this.regionManager.Regions[“MyRegion”];
foreach (var view in region.Views)
In case you want to remove the registered view from the region before the region is displayed, take into account that Prism offers no possibility to unregister a view from a region in the
RegionViewRegistry out of the box, so you would have to wait for the region to be added to the visual tree in order to remove views from it. If you need to do so, you would have to modify the
RegionViewRegistry or the AutoPopulateBehavior to support this (for example, adding an
UnregisterViewWithRegion method to the RegionViewRegistry).
I hope you find this helpful.
Guido Leandro Maliandi