Quantcast
Channel: patterns & practices: Prism
Viewing all articles
Browse latest Browse all 1878

Commented Issue: DelayedRegionCreationBehavior garbage collected in non-FrameworkElement regions [8521]

$
0
0
In regions whose target element inherits from FrameworkElement, a reference of the DelayedRegionCreationBehavior is kept in the control, since there is an event subscription to the Loaded event in the control, handled by a method in the aforementioned behavior.
 
In cases where the target element does not inherit from FrameworkElement, this event subscription isn’t done, and thus, there is no element holding a strong reference to the DelayedRegionCreationBehavior. Therefore, if the garbage collector attempts to remove unused objects before the UpdateRegions method in the RegionManager is called, the DelayedRegionCreationBehavior will be garbage collected before the actual region is created by it, thus causing the actual region not to be created by the behavior.
 
A possible workaround could be to store a reference to the behaviors in the region manager, like this:
 
RegionManger before:
private static void CreateRegion(DependencyObject element)
{
IServiceLocator locator = ServiceLocator.Current;
DelayedRegionCreationBehavior regionCreationBehavior = locator.GetInstance<DelayedRegionCreationBehavior>();
regionCreationBehavior.TargetElement = element;
regionCreationBehavior.Attach();
}
 
RegionManger after:
private static void CreateRegion(DependencyObject element)
{
IServiceLocator locator = ServiceLocator.Current;
DelayedRegionCreationBehavior regionCreationBehavior = locator.GetInstance<DelayedRegionCreationBehavior>();
regionCreationBehavior.TargetElement = element;
regionCreationBehavior.Attach();
_delayedBehaviors.Add(regionCreationBehavior);
}
private static List<DelayedRegionCreationBehavior> _delayedBehaviors = new List<DelayedRegionCreationBehavior>();"
 
Thanks,
 
Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi
Comments: ** Comment from web user: nitroxn **

Can you show me a code snippet of what you did to resolve this issue with the RibbonDefaultPageCategory issue. I am also experiencing something similar. The regions are registered and the view gets created in debug mode when the framework version is 4.0 but it does not work when the application is run in release mode or with framework set to .net 4.5.


Viewing all articles
Browse latest Browse all 1878

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>