Behavior that removes the RegionManager attached property of all the views in a region once the RegionManager property of a region becomes null. This is useful when removing views with nested regions, to ensure these nested regions get removed from the RegionManager as well. This behavior does not apply by default. In order to activate it, the ClearChildViews attached property must be set to True in the view containing the affected child regions.
Inheritance: Microsoft.Practices.Prism.Regions.RegionBehavior
        public void WhenClearChildViewsPropertyIsNotSet_ThenChildViewsRegionManagerIsNotCleared()
        {
            var regionManager = new MockRegionManager();

            var region = new Region();
            region.RegionManager = regionManager;

            var behavior = new ClearChildViewsRegionBehavior();
            behavior.Region = region;
            behavior.Attach();

            var childView = new MockFrameworkElement();
            region.Add(childView);

            Assert.AreEqual(regionManager, childView.GetValue(RegionManager.RegionManagerProperty));

            region.RegionManager = null;

            Assert.AreEqual(regionManager, childView.GetValue(RegionManager.RegionManagerProperty));
        }
        public async Task WhenClearChildViewsPropertyIsNotSet_ThenChildViewsRegionManagerIsNotCleared()
        {
            await ExecuteOnUIThread(() =>
                {
                    var regionManager = new MockRegionManager();

                    var region = new Region() { RegionManager = regionManager };

                    var behavior = new ClearChildViewsRegionBehavior() { Region = region };
                    behavior.Attach();

                    var childView = new MockFrameworkElement();
                    region.Add(childView);

                    Assert.AreEqual(regionManager, childView.GetValue(RegionManager.RegionManagerProperty));

                    region.RegionManager = null;

                    Assert.AreEqual(regionManager, childView.GetValue(RegionManager.RegionManagerProperty));
                });
        }