I'm developing an WPF application with PRISM 5.0.
At some point I want to deactivate all active views in specific region.
IRegion contentRegion = _regionManager.Regions
    .First(region => region.Name == RegionNames.ContentRegion);
foreach (object view in contentRegion.ActiveViews)
{
    contentRegion.Deactivate(view);
}
But at this point I get an exception:
System.InvalidOperationException was unhandled by user code
  HResult=-2146233079
  Message=Deactivation is not possible in this type of region.
  Source=Microsoft.Practices.Prism.Composition
  StackTrace: ...
  InnerException: 
My region is only declared at base view Shell.xaml as
<Border Grid.Column="1" BorderBrush="#193441"  BorderThickness="2,2,2,2">
    <ContentControl regions:RegionManager.RegionName="ContentRegion" />
</Border>
				
                        
Region Deactivate depends on implementation
Behaviour of
DeactivateonIRegiondepends on it's implementation that you set declaring region in xaml.Its implementation is set by type of control that is set at view (main view Shell.xaml here).
Possible implementations and how to set them:
SingleActiveRegion(set byContentControl): only one active region at a time. It automatycly deactivate views at other view activation.AllActiveRegion(set byItemsControl): All views are visible and active. CallingDeactivatewill causeInvalidOperationException.Region(set bySelector): It allows multiple active and deactive views.It's widely described in this post.
Change region declaration
For me it is more comfortable to had only one active view in this region, so I've changed region declaration in
Shell.xamlto:And now my region is type of
SingleActiveRegionwhere I don't have to callDeactivate.When can i use
DeactivateContentControland you want to deactivate only active viewSelectorcontrol in .xaml - then you can useDeactivate