Exemplo n.º 1
0
        protected virtual void FixupLayout(LayoutRoot layout)
        {
            //fix container panes
            foreach (var lcToAttach in layout.Descendents().OfType <ILayoutPreviousContainer>().Where(lc => lc.PreviousContainerId != null))
            {
                var paneContainerToAttach = layout.Descendents().OfType <ILayoutPaneSerializable>().FirstOrDefault(lps => lps.Id == lcToAttach.PreviousContainerId);
                if (paneContainerToAttach == null)
                {
                    throw new ArgumentException(string.Format("Unable to find a pane with id ='{0}'", lcToAttach.PreviousContainerId));
                }

                lcToAttach.PreviousContainer = paneContainerToAttach as ILayoutContainer;
            }


            //now fix the content of the layoutcontents
            foreach (var lcToFix in layout.Descendents().OfType <LayoutAnchorable>().Where(lc => lc.Content == null).ToArray())
            {
                LayoutAnchorable previousAchorable = null;
                if (lcToFix.ContentId != null)
                {
                    //try find the content in replaced layout
                    previousAchorable = _previousAnchorables.FirstOrDefault(a => a.ContentId == lcToFix.ContentId);
                }

                if (LayoutSerializationCallback != null)
                {
                    var args = new LayoutSerializationCallbackEventArgs(lcToFix, previousAchorable != null ? previousAchorable.Content : null);
                    LayoutSerializationCallback(this, args);
                    if (args.Cancel)
                    {
                        lcToFix.Close();
                    }
                    else if (args.Content != null)
                    {
                        lcToFix.Content = args.Content;
                    }
                    else if (args.Model.Content != null)
                    {
                        lcToFix.Hide(false);
                    }
                }
                else if (previousAchorable == null)
                {
                    lcToFix.Hide(false);
                }
                else
                {
                    lcToFix.Content    = previousAchorable.Content;
                    lcToFix.IconSource = previousAchorable.IconSource;
                }
            }


            foreach (var lcToFix in layout.Descendents().OfType <LayoutDocument>().Where(lc => lc.Content == null).ToArray())
            {
                LayoutDocument previousDocument = null;
                if (lcToFix.ContentId != null)
                {
                    //try find the content in replaced layout
                    previousDocument = _previousDocuments.FirstOrDefault(a => a.ContentId == lcToFix.ContentId);
                }

                if (LayoutSerializationCallback != null)
                {
                    var args = new LayoutSerializationCallbackEventArgs(lcToFix, previousDocument != null ? previousDocument.Content : null);
                    LayoutSerializationCallback(this, args);

                    if (args.Cancel)
                    {
                        lcToFix.Close();
                    }
                    else if (args.Content != null)
                    {
                        lcToFix.Content = args.Content;
                    }
                    else if (args.Model.Content != null)
                    {
                        lcToFix.Close();
                    }
                }
                else if (previousDocument == null)
                {
                    lcToFix.Close();
                }
                else
                {
                    lcToFix.Content    = previousDocument.Content;
                    lcToFix.IconSource = previousDocument.IconSource;
                }
            }

            layout.CollectGarbage();
        }
Exemplo n.º 2
0
        protected virtual void FixupLayout(LayoutRoot layout)
        {
            //fix container panes
            foreach (var lcToAttach in layout.Descendents().OfType<ILayoutPreviousContainer>().Where(lc => lc.PreviousContainerId != null))
            {
                var paneContainerToAttach = layout.Descendents().OfType<ILayoutPaneSerializable>().FirstOrDefault(lps => lps.Id == lcToAttach.PreviousContainerId);
                if (paneContainerToAttach == null)
                    throw new ArgumentException(string.Format("Unable to find a pane with id ='{0}'", lcToAttach.PreviousContainerId));

                lcToAttach.PreviousContainer = paneContainerToAttach as ILayoutContainer;
            }


            //now fix the content of the layoutcontents
            foreach (var lcToFix in layout.Descendents().OfType<LayoutAnchorable>().Where(lc => lc.Content == null).ToArray())
            {
                LayoutAnchorable previousAchorable = null;
                if (lcToFix.ContentId != null)
                { 
                    //try find the content in replaced layout
                    previousAchorable = _previousAnchorables.FirstOrDefault(a => a.ContentId == lcToFix.ContentId);
                }

                if (LayoutSerializationCallback != null)
                {
                    var args = new LayoutSerializationCallbackEventArgs(lcToFix, previousAchorable != null ? previousAchorable.Content : null);
                    LayoutSerializationCallback(this, args);
                    if (args.Content != null)
                        lcToFix.Content = args.Content;
                    else if (args.Model.Content != null)
                        lcToFix.Hide(false);
                }
                else if (previousAchorable == null)
                    lcToFix.Hide(false);
                else
                {
                    lcToFix.Content = previousAchorable.Content;
                    lcToFix.IconSource = previousAchorable.IconSource;
                }
            }


            foreach (var lcToFix in layout.Descendents().OfType<LayoutDocument>().Where(lc => lc.Content == null).ToArray())
            {
                LayoutDocument previousDocument = null;
                if (lcToFix.ContentId != null)
                {
                    //try find the content in replaced layout
                    previousDocument = _previousDocuments.FirstOrDefault(a => a.ContentId == lcToFix.ContentId);
                }

                if (LayoutSerializationCallback != null)
                {
                    var args = new LayoutSerializationCallbackEventArgs(lcToFix, previousDocument != null ? previousDocument.Content : null);
                    LayoutSerializationCallback(this, args);
                    if (args.Content != null)
                        lcToFix.Content = args.Content;
                    else if (args.Model.Content != null)
                        lcToFix.Close();
                }
                else if (previousDocument == null)
                    lcToFix.Close();
                else
                    lcToFix.Content = previousDocument.Content;
            }


            layout.CollectGarbage();
        }
Exemplo n.º 3
0
        protected virtual void FixupLayout(LayoutRoot layout)
        {
            //fix container panes
            foreach (var lcToAttach in layout.Descendents().OfType <ILayoutPreviousContainer>().Where(lc => lc.PreviousContainerId != null))
            {
                var paneContainerToAttach = layout.Descendents().OfType <ILayoutPaneSerializable>().FirstOrDefault(lps => lps.Id == lcToAttach.PreviousContainerId);
                if (paneContainerToAttach == null)
                {
                    throw new ArgumentException($"Unable to find a pane with id ='{lcToAttach.PreviousContainerId}'");
                }
                lcToAttach.PreviousContainer = paneContainerToAttach as ILayoutContainer;
            }

            //now fix the content of the layout anchorable contents
            foreach (var lcToFix in layout.Descendents().OfType <LayoutAnchorable>().Where(lc => lc.Content == null).ToArray())
            {
                LayoutAnchorable previousAchorable = null;                            //try find the content in replaced layout
                if (lcToFix.ContentId != null)
                {
                    previousAchorable = _previousAnchorables.FirstOrDefault(a => a.ContentId == lcToFix.ContentId);
                }

                if (LayoutSerializationCallback != null)
                {
                    // Ask client application via callback if item should be deserialized
                    var args = new LayoutSerializationCallbackEventArgs(lcToFix, previousAchorable?.Content);
                    LayoutSerializationCallback(this, args);
                    if (args.Cancel)
                    {
                        lcToFix.Close();
                    }
                    else if (args.Content != null)
                    {
                        lcToFix.Content = args.Content;
                    }
                    else if (args.Model.Content != null)
                    {
                        lcToFix.Hide(false);                                   // hide layoutanchorable if client app supplied no content
                    }
                }
                else if (previousAchorable == null)                  // No Callback and no provious document -> skip this
                {
                    lcToFix.Hide(false);
                }
                else
                {                   // No Callback but previous anchoreable available -> load content from previous document
                    lcToFix.Content    = previousAchorable.Content;
                    lcToFix.IconSource = previousAchorable.IconSource;
                }
            }

            //now fix the content of the layout document contents
            foreach (var lcToFix in layout.Descendents().OfType <LayoutDocument>().Where(lc => lc.Content == null).ToArray())
            {
                LayoutDocument previousDocument = null;                               //try find the content in replaced layout
                if (lcToFix.ContentId != null)
                {
                    previousDocument = _previousDocuments.FirstOrDefault(a => a.ContentId == lcToFix.ContentId);
                }

                if (LayoutSerializationCallback != null)
                {
                    // Ask client application via callback if this realy should be deserialized
                    var args = new LayoutSerializationCallbackEventArgs(lcToFix, previousDocument?.Content);
                    LayoutSerializationCallback(this, args);

                    if (args.Cancel)
                    {
                        lcToFix.Close();
                    }
                    else if (args.Content != null)
                    {
                        lcToFix.Content = args.Content;
                    }
                    else if (args.Model.Content != null)                      // Close document if client app supplied no content
                    {
                        lcToFix.Close();
                    }
                }
                else if (previousDocument == null)                  // No Callback and no provious document -> skip this
                {
                    lcToFix.Close();
                }
                else
                {                       // No Callback but previous document available -> load content from previous document
                    lcToFix.Content    = previousDocument.Content;
                    lcToFix.IconSource = previousDocument.IconSource;
                }
            }

            layout.CollectGarbage();
        }