protected override void OnClosed(EventArgs e)
        {
            var root = Model.Root;

            if (root != null)
            {
                LayoutRoot layoutRoot = root as LayoutRoot;
                if (layoutRoot != null)
                {
                    layoutRoot.Updated -= OnRootUpdated;
                }

                root.Manager.RemoveFloatingWindow(this);
                root.CollectGarbage();
            }
            if (_overlayWindow != null)
            {
                _overlayWindow.Close();
                _overlayWindow = null;
            }

            base.OnClosed(e);

            if (!CloseInitiatedByUser && (root != null))
            {
                root.FloatingWindows.Remove(_model);
            }

            // We have to clear binding instead of creating a new empty binding.
            BindingOperations.ClearBinding(_model, VisibilityProperty);

            _model.PropertyChanged -= new System.ComponentModel.PropertyChangedEventHandler(_model_PropertyChanged);

            Activated -= LayoutAnchorableFloatingWindowControl_Activated;
        }
        protected override void OnClosed(EventArgs e)
        {
            var root = Model.Root;

            if (root != null)
            {
                root.Manager.RemoveFloatingWindow(this);
                root.CollectGarbage();
            }
            if (_overlayWindow != null)
            {
                _overlayWindow.Close();
                _overlayWindow = null;
            }

            base.OnClosed(e);

            if (!CloseInitiatedByUser && (root != null))
            {
                root.FloatingWindows.Remove(_model);
            }

            _model.PropertyChanged -= new System.ComponentModel.PropertyChangedEventHandler(_model_PropertyChanged);
            IsVisibleChanged       -= this.LayoutAnchorableFloatingWindowControl_IsVisibleChanged;
            BindingOperations.ClearBinding(this, VisibilityProperty);
            BindingOperations.ClearBinding(this, SingleContentLayoutItemProperty);
        }
        protected override void OnClosed(EventArgs e)
        {
            var root = Model.Root;

            if (root != null)
            {
                root.Manager.RemoveFloatingWindow(this);
                root.CollectGarbage();
            }
            if (_overlayWindow != null)
            {
                _overlayWindow.Close();
                _overlayWindow = null;
            }

            base.OnClosed(e);

            if (!CloseInitiatedByUser && (root != null))
            {
                root.FloatingWindows.Remove(_model);
            }

            SetBinding(VisibilityProperty, string.Empty);

            _model.PropertyChanged -= new System.ComponentModel.PropertyChangedEventHandler(_model_PropertyChanged);
        }
        protected override void OnClosed(EventArgs e)
        {
            if (_overlayWindow != null)
            {
                _overlayWindow.Close();
                _overlayWindow = null;
            }

            base.OnClosed(e);

            _model.PropertyChanged -= new System.ComponentModel.PropertyChangedEventHandler(_model_PropertyChanged);
            IsVisibleChanged       -= this.LayoutAnchorableFloatingWindowControl_IsVisibleChanged;
            BindingOperations.ClearBinding(this, VisibilityProperty);
            BindingOperations.ClearBinding(this, SingleContentLayoutItemProperty);
        }