/// <summary> /// Close this document removing it from its parent container /// </summary> /// <remarks>Use this function to close a document and remove it from its parent container. Please note /// that if you simply remove it from its parent <see cref="DocumentPane"/> without call this method, events like /// <see cref="OnClosing"/>/<see cref="OnClosed"/> are not called. /// </remarks> public override bool Close() { if (!IsCloseable) { return(false); } ////if documents are attached to an external source via DockingManager.DocumentsSource ////let application host handle the document closing by itself //if (Manager.DocumentsSource != null) //{ // //return Manager.FireRequestDocumentCloseEvent(this); // Manager.HandleDocumentClose(this); //} DocumentClosingCancelEventArgs e = new DocumentClosingCancelEventArgs(false, this); OnClosing(e); if (e.Cancel) { return(false); } DockingManager oldManager = Manager; if (oldManager != null) { oldManager.FireDocumentClosingEvent(e); } if (e.Cancel) { return(false); } InternalClose(); OnClosed(); //if documents are attached to an external source via DockingManager.DocumentsSource //let application host handle the document closing by itself //if (oldManager != null && // oldManager.DocumentsSource != null) //{ // oldManager.HandleDocumentClose(this); //} if (oldManager != null) { DocumentClosedEventArgs documentClosedArgs = new DocumentClosedEventArgs(this); oldManager.FireDocumentClosedEvent(documentClosedArgs); } Debug.Assert(Parent == null, "Parent MUST bu null after Doc is closed"); return(true); }
/// <summary> /// Close this document removing it from its parent container /// </summary> /// <remarks>Use this function to close a document and remove it from its parent container. Please note /// that if you simply remove it from its parent <see cref="DocumentPane"/> without call this method, events like /// <see cref="OnClosing"/>/<see cref="OnClosed"/> are not called. /// <para> /// Note:<see cref="DockableContent"/> cannot be closed: AvalonDock simply hide a <see cref="DockableContent"/> removing all the reference to it. /// </para> /// </remarks> public bool Close() { if (!IsCloseable) { return(false); } //if documents are attached to an external source via DockingManager.DocumentsSource //let application host handle the document closing by itself if (Manager.DocumentsSource != null) { return(Manager.FireRequestDocumentCloseEvent(this)); } CancelEventArgs e = new CancelEventArgs(false); OnClosing(e); if (e.Cancel) { return(false); } DockingManager oldManager = Manager; if (Manager != null) { Manager.FireDocumentClosingEvent(e); } if (e.Cancel) { return(false); } InternalClose(); OnClosed(); if (oldManager != null) { oldManager.FireDocumentClosedEvent(); } //if (Parent != null) // throw new InvalidOperationException(); Debug.Assert(Parent == null, "Parent MUST bu null after Doc is closed"); return(true); }