Prism code sample learning: 03-Custom Regions

1 minute read

Prism code sample learning: 03-Custom Regions


This is a continuation of the following article.


In this sample, RegionAdapterBase class is used to give the name of the region to the existing control.

<Window x:Class="Regions.Views.MainWindow"
        Title="Shell" Height="350" Width="525">
        <StackPanel prism:RegionManager.RegionName="ContentRegion" />
    public class StackPanelRegionAdapter : RegionAdapterBase<StackPanel>
        public StackPanelRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory)
            : base(regionBehaviorFactory)


        protected override void Adapt(IRegion region, StackPanel regionTarget)
            region.Views.CollectionChanged += (s, e) =>
                if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
                    foreach (FrameworkElement element in e.NewItems)

                //handle remove

        protected override IRegion CreateRegion()
            return new AllActiveRegion();

    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : PrismApplication
        ... (abridgement) ...

        protected override void ConfigureRegionAdapterMappings(RegionAdapterMappings regionAdapterMappings)
            regionAdapterMappings.RegisterMapping(typeof(StackPanel), Container.Resolve<StackPanelRegionAdapter>());

–Region mapping is registered by ConfigureRegionAdapterMappings method.
–The ConfigureRegionAdapterMappings method is called inside the Bootstrap.Run method
–RegionAdapterBase \ <T > class is here [
–Adapt method is called in Initialize method
–It seems that the processing at the time of addition / deletion can be implemented for the child elements added to View by the Adapt method.
–Called by the Initialize method implemented in this class in the IRegionAdapter.Initialize method.
–The above interface + method name defines Implementation of explicit interface
–The CreateRegion method is also called inside the Initialilze method.
–Click here for AllActiveRegion class (
-Region has an active state and an inactive state
–I couldn’t understand the meaning of the property by looking at Definition destination. However, as far as I can guess from the text, can performance be improved by managing the active Region or the state? I think that the.

in conclusion

This time, I mainly read the source code of the RegionAdapterBase class.
Some implementations are unknown at this stage, so I’ll continue reading to clarify them.
Next time, I will look at 04-View Discovery.