a bug?Region delete view then clear RegionManager

Topics: Prism v2 - WPF 3.5
Mar 26, 2009 at 9:04 AM
   When we create Region with new RegionManager with follow code.
   _regionManager.Regions[region].Add(currentView,"",true);

  the currentView also have a region,so I can get the RegionManager with RegionManager.GetRegionManager(currentView).It will working.
  But sometimes we need remove the currentView from new created region.So we also want to clear the currentView's AttachProperty (RegionManager.RegionManagerProperty)

we can lookup remove method with region 

        public virtual void Remove(object view)
        {
            ItemMetadata itemMetadata = this.GetItemMetadataOrThrow(view);

            this.ItemMetadataCollection.Remove(itemMetadata);

            DependencyObject dependencyObject = view as DependencyObject;
            if (dependencyObject != null && Regions.RegionManager.GetRegionManager(dependencyObject) == this.RegionManager)
            {
                dependencyObject.ClearValue(Regions.RegionManager.RegionManagerProperty);
            }
        }

Now,if the RegionManager created with new RegionManager.Then the view can't clear the RegionManager.RegionManagerProperty.
I think this is bug.
Mar 27, 2009 at 1:06 AM
Can any one help me?
Apr 29, 2009 at 8:28 AM
Hi,

 I am facing similar issue, can't remove a region form the RegionManager.

Can someone please suggest a solution for this,

Thank you,
Regards,
Apr 29, 2009 at 7:09 PM
Edited Apr 29, 2009 at 7:11 PM

Hi Clingingboy,

 

This is the intended behavior of the Remove() method. That is because, in case you have manually set a RegionManager to your view (instead of using the overload of the Region that does this) , perhaps you do not want to lose it “automatically” when calling this method.

 

To clear the property manually you can do something like this:

regionManager.Regions["MainRegion"].Remove(currentView);

      DependencyObject dependencyObject = currentView as DependencyObject;

if (dependencyObject != null)

{

dependencyObject.ClearValue(RegionManager.RegionManagerProperty); // IRegionManager viewRegionManager = RegionManager.GetRegionManager(view); viewRegionManager will be null

}

 

Please let me know if this helps.

 

Damian Schenkelman

http://blogs.southworks.net/dschenkelman