DockingManager.DocumentsSource

Oct 22, 2009 at 5:51 PM

Hello,

The DocumentsSource prop doesn't seem to react to a Clear instruction on the Collection.  It does work when you remove each item seperately, ex:

this works:

while (AvalonDocs.Count > 0)
                  AvalonDocs.RemoveAt(AvalonDocs.Count - 1);

 

this doesn't:

AvalonDocs.Clear();

 

Oct 26, 2009 at 7:02 AM

Please refer to this patch made by me http://avalondock.codeplex.com/Project/Download/FileDownload.aspx?DownloadId=88403.

Also look at the thread that I have started in the issue tracker section where I have stated that the code that you described above( while(AvalonDocc.Count > 0) ... ) will work sometimes, but in some very specific cases it gives me and exception.

I have resolved what is the problem and posted a patch. If you dont want to download the patch here is the code in DockingManager.cs that needs to be fixed.

 

void DocumentsSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == NotifyCollectionChangedAction.Reset)
            {
				DocumentContent[] docs = this.Documents;
				ObservableCollection<DocumentContent> documentsToClose = new ObservableCollection<DocumentContent>();

				foreach (DocumentContent doc in docs)
				{
					if (doc.Parent is DocumentPane)
					{
						if ((doc.Parent as DocumentPane).IsMainDocumentPane == false)
						{
							documentsToClose.Add(doc);
						}
					}
				}

				foreach (DocumentContent doc in documentsToClose)
				{
					doc.InternalClose();
				}

				foreach (DocumentContent doc in docs)
                    doc.InternalClose();
            }

            if (MainDocumentPane == null)

 

 

 

void DocumentsSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == NotifyCollectionChangedAction.Reset)
            {
DocumentContent[] docs = this.Documents;
ObservableCollection<DocumentContent> documentsToClose = new ObservableCollection<DocumentContent>();
foreach (DocumentContent doc in docs)
{
if (doc.Parent is DocumentPane)
{
if ((doc.Parent as DocumentPane).IsMainDocumentPane == false)
{
documentsToClose.Add(doc);
}
}
}
foreach (DocumentContent doc in documentsToClose)
{
doc.InternalClose();
}
foreach (DocumentContent doc in docs)
                    doc.InternalClose();
            }
            if (MainDocumentPane == null)

 

Oct 26, 2009 at 7:57 AM

Ok, thanks for his. I'll have to grab the code first and than apply your patch.

 

Oct 29, 2009 at 3:59 PM

Well, now I have changed my code above to support closing and closed events. Simply instead internalClose(0 method write Close(), and in the Close() method of DocumentContent comment out the lines described below

 

public bool Close()
        {
			
            //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);
...

I have absolutely no idea to what purpose is there RequestDocumentCloseEvent because we can attach to closing event or closed event of documentContent and remove the content from DocumentsSource.

Cheers

 

Oct 29, 2009 at 5:17 PM

It's just a more convenient way to do the same thing!

Nov 2, 2009 at 6:14 AM

Yeah, but if I have only the RequestDocumentCloseEvent I can not do whatever is happening in the InternalClose method (where it is happening a lot of things), and I can not do the Clear() method of a documents source

because the documents just stay. So I think that the call to the InternalClose is a must.

So instead of attaching to a RequestDocumentCloseEvent we could attach to a DocumentClosed event and remove it from DocumentsSource.

Cheers