private void UnRegisterRelationUserControl(ref UserControl uc, string vcKey, bool isUnRegisterVM) { if (uc == null) { return; } string uctypekey = GetViewControlKey(uc.GetType(), vcKey); var ucchilds = uc.Descendents(); foreach (UserControl t in ucchilds.OfType <UserControl>()) { UserControl t2 = t; string t2key = GetViewControlKey(t2.GetType(), vcKey); UnRegisterRelationUserControl(ref t2, vcKey, isUnRegisterVM); if (t2 != null) { if (t2.DataContext != null) { if (isUnRegisterVM) { if (t2.DataContext is ViewModelBase) { ViewModelLocator.Instance.UnRegisterViewModel(t2.DataContext.GetType(), vcKey); } } t2.DataContext = null; } if (t2.Content != null) { GC.SuppressFinalize(t2.Content); t2.Content = null; } } if (ViewControls.ContainsKey(t2key)) { ViewControls.Remove(t2key); } if (t2 != null) { GC.SuppressFinalize(t2); } } }