private void Views_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { Window owner = _ownerWeakReference.Target as Window; if (owner == null) { Detach(); return; } if (e.Action == NotifyCollectionChangedAction.Add) { foreach (object view in e.NewItems) { UserControlBase content = view as UserControlBase; if (content != null) { Window window = new Window(); window.Activated += new EventHandler(window_Activated); window.Deactivated += new EventHandler(window_Deactivated); window.Style = _windowStyle; if (content != null) { window.Title = content.Title; window.Height = (Double.IsNaN(content.Height) ? content.ActualHeight + 50 : content.Height + 50); window.Width = (Double.IsNaN(content.Width) ? content.ActualWidth + 30 : content.Width + 30); content.InitEvent(window.Close); } window.Content = view; window.WindowStartupLocation = WindowStartupLocation.CenterScreen; window.Closed += new EventHandler(window_Closed); window.Owner = owner; window.Show(); } } } else if (e.Action == NotifyCollectionChangedAction.Remove) { foreach (object view in e.OldItems) { Window window = GetContainerWindow(owner, view); if (window != null) { window.Close(); } } } }