private void RemoveDynamicPanel(LayoutAnchorable anchorable) { var invalidationSubscriptions = InvalidationSubscriptions.Where(o => o.Object == anchorable).ToList(); foreach (var subscription in invalidationSubscriptions) { subscription.Break(); InvalidationSubscriptions.Remove(subscription); } var view = anchorable.Content.SafeCast <UserControl>(); var viewModel = view.DataContext; view.DataContext = null; if (viewModel is IDestructible destructible) { destructible.TearDown(); } anchorable.Hiding -= OnRemoveHandler; if (anchorable.GetRoot() == DockingView.DockingManager.Layout) { anchorable.Close(); } ActivePanels.Remove(anchorable); }