Prism: InvalidOperationException on region deactivation. "Deactivation is not possible in this type of region."

I am developing a WPF application with PRISM 5.0.

At some point, I want to deactivate all active views in a specific area.

IRegion contentRegion = _regionManager.Regions
    .First(region => region.Name == RegionNames.ContentRegion);

foreach (object view in contentRegion.ActiveViews)
{
    contentRegion.Deactivate(view);
}

      

But at the moment I am getting 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 scope is only declared in basic Shell.xaml as

<Border Grid.Column="1" BorderBrush="#193441"  BorderThickness="2,2,2,2">
    <ContentControl regions:RegionManager.RegionName="ContentRegion" />
</Border>

      

+3


source to share


1 answer


Region Deactivate implementation dependent

Behavior Deactivate

on IRegion

depends on the realization that you were asked to declare the area in xaml.

Its implementation is given by the control type set in the view (the main view is Shell.xaml here).

Possible implementations and how to install them:

  • SingleActiveRegion

    (set ContentControl

    ): only one hot spot at a time. It will automatically deactivate views on another activation.
  • AllActiveRegion

    (set ItemsControl

    ): all views are visible and active. The call Deactivate

    will result in InvalidOperationException

    .
  • Region

    (set Selector

    ): Allows multiple active and deactivated views.

It is described extensively in this post .



Declaring the scope of change

It's more convenient for me to have only one active view in this region, so I changed the region declaration in Shell.xaml

to:

<Border Grid.Column="1" BorderBrush="#193441"  BorderThickness="2,2,2,2">
    <ContentControl regions:RegionManager.RegionName="ContentRegion" />
</Border>

      

And now my region is a type SingleActiveRegion

where I don't need to call Deactivate

.

When can I use Deactivate

  • If you have ContentControl

    and want to deactivate only active browsing
  • If you want to keep multiple active views you must use the control Selector

    in the .xaml - then you can useDeactivate

+5


source







All Articles