void UnregisterRegionManagers(DependencyObject view, UnregisterBehavior behavior) { if (view != null) { if (this.HoldsRegionManager(view)) { var manager = this.regionManagers[view]; manager.Shutdown(); this.regionManagers.Remove(view); } if (this.closableObjects.Contains(view)) { this.closableObjects.Remove(view); } if (behavior == UnregisterBehavior.WholeLogicalTreeChain) { #if SILVERLIGHT var children = LogicalTreeHelper.GetChildren((FrameworkElement)view); #else var children = LogicalTreeHelper.GetChildren(view); #endif foreach (var child in children) { this.UnregisterRegionManagers(child as DependencyObject, behavior); } } } }
/// <summary> /// Unregisters the region manager owned by the supplied owner. /// </summary> /// <param name="owner">The owner of the region manager to unregister.</param> /// <param name="behavior">How to manage reguion manager found in child/nested views.</param> /// <exception cref="NotSupportedException">A NotSupportedException is raised if this service has no region manager registered for the supplied owner. Use HoldsRegionManager() to test.</exception> public void UnregisterRegionManager(DependencyObject owner, UnregisterBehavior behavior) { if (!this.HoldsRegionManager(owner)) { throw new NotSupportedException(); } this.UnregisterRegionManagers(owner, behavior); }