[1.3] DocumentContent.Show Problems

Jul 1, 2010 at 3:34 PM

I've been having trouble getting a new DocumentContent instance to show as a floating window when calling the Show method and setting showAsFloatingWindow to true. Even in the sample project you provide, in the CreateDocumentContent function, setting the argument for showAsFloatingWindow to true in the Show method results in an unhandled NullReferenceException.

Could you provide some clarity on how to use the Show method in this manner? 

Thanks

Jul 1, 2010 at 7:17 PM
Hi, it's a bug, thx for the feedback, now it's fixed in version 1.3.3571, Ado
Jul 1, 2010 at 8:47 PM

Excellent, thank you.

Sep 21, 2011 at 11:04 PM

Hi, I'm using 1.3.3592 and it appears there is still a bug there.

Calling DocumentContent.Show(true) when the document is already in a document pane doesn't work. And calling DocumentContent.Show(true) when the document is floating puts the document back to the previous container (ie, the document pane).

The problem seems to be here:

        internal void Show(DocumentContent document, bool floating)
        {
            bool found = Documents.FirstOrDefault(d => d == document) != null;

            if (!found && MainDocumentPane != null)
            {
                if (document.Parent is DocumentPane)
                {
                    ((DocumentPane)document.Parent).Items.Clear();
                }

                if (floating)
                {
                    DocumentFloatingWindow floatingWindow = new DocumentFloatingWindow(this);
                    floatingWindow.Owner = Window.GetWindow(this);
                    floatingWindow.Content = document;
                    floatingWindow.Show();
                }
                else
                    MainDocumentPane.Items.Insert(0, document);
            }
            else if (found && document.ContainerPane is FloatingDocumentPane)
            {
                var containerPane = document.ContainerPane as FloatingDocumentPane;
                DocumentPane previousPane = containerPane.PreviousPane;
                int arrayIndexPreviuosPane = containerPane.ArrayIndexPreviousPane;
                //if previous pane exist that redock to it
                if (previousPane == null ||
                    previousPane.GetManager() != this)
                {
                    previousPane = MainDocumentPane;
                    arrayIndexPreviuosPane = 0;
                }

                if (previousPane != null)
                {
                    if (arrayIndexPreviuosPane > previousPane.Items.Count)
                        arrayIndexPreviuosPane = previousPane.Items.Count;

                    previousPane.Items.Insert(arrayIndexPreviuosPane,
                        containerPane.RemoveContent(0));
                }

                containerPane.FloatingWindow.Close();
            }

        }

The problem here, is that if the DocumentContent is already in a floating window, calling document.Show(true) will put it back on the document pane. Whereas if the document is already in the document pane, calling document.Show(true) won't do anything.

I fixed it in my code with something like this:

        internal void Show(DocumentContent document, bool floating)
        {
            bool found = Documents.FirstOrDefault(d => d == document) != null;

            if (!found && MainDocumentPane != null)
            {
                if (document.Parent is DocumentPane)
                {
                    ((DocumentPane)document.Parent).Items.Clear();
                }

                if (floating)
                {
                    DocumentFloatingWindow floatingWindow = new DocumentFloatingWindow(this);
                    floatingWindow.Owner = Window.GetWindow(this);
                    floatingWindow.Content = document;
                    floatingWindow.Show();
                }
                else
                    MainDocumentPane.Items.Insert(0, document);
            }
            else if (found && document.ContainerPane is FloatingDocumentPane)
            {
                if (!floating)
                {
                    var containerPane = document.ContainerPane as FloatingDocumentPane;
                    DocumentPane previousPane = containerPane.PreviousPane;
                    int arrayIndexPreviuosPane = containerPane.ArrayIndexPreviousPane;
                    //if previous pane exist that redock to it
                    if (previousPane == null ||
                        previousPane.GetManager() != this)
                    {
                        previousPane = MainDocumentPane;
                        arrayIndexPreviuosPane = 0;
                    }

                    if (previousPane != null)
                    {
                        if (arrayIndexPreviuosPane > previousPane.Items.Count)
                            arrayIndexPreviuosPane = previousPane.Items.Count;

                        previousPane.Items.Insert(arrayIndexPreviuosPane,
                            containerPane.RemoveContent(0));
                    }

                    containerPane.FloatingWindow.Close();
                }
            }
            else if (found && document.ContainerPane is DocumentPane)
            {
                if (floating)
                {
                    DocumentFloatingWindow floatingWindow = new DocumentFloatingWindow(this);
                    floatingWindow.Owner = Window.GetWindow(this);
                    floatingWindow.Content = document;
                    floatingWindow.Show();
                }
            }
        }

Thanks!

k