This project is read-only.

[Version 2.0] How to clear "LastFocusedDocument"?

May 8, 2012 at 11:51 AM

Well, I'm not sure whether this is a bug or not...perhaps it's something wrong in my implementation.

I add a LayoutDocument, so that it will be focused (i.e. ActiveContent refers to it). Then I remove it, by closing it. Also, the ActiveContent property is ensured to "null".

I'd expect the LayoutDocument instance being destroyed, since it's actually missing from the pane collection. The problem is that the instance is still alive, being hung by a LastFocusedDocument reference. That is clear if you inspect the memory with any profiler.

Well, if I have another document to display, I could switch the activity to that instance, but...what if there's no more docs?

Specifically, in the LayoutRoot class, where both ActiveContent and LastFocusedDocument are declared, might it changed the setter as follows?

        public LayoutContent ActiveContent
        {
            get { return _activeContent; }
            set
            {
                if (_activeContent != value)
                {
                    RaisePropertyChanging("ActiveContent");
                    if (_activeContent != null)
                        _activeContent.IsActive = false;
                    _activeContent = value;
                    if (_activeContent != null)
                        _activeContent.IsActive = true;
                    RaisePropertyChanged("ActiveContent");

                    //if (_activeContent != null && (_activeContent.Parent is LayoutDocumentPane || _activeContent is LayoutDocument))
                    if (_activeContent == null || _activeContent.Parent is LayoutDocumentPane || _activeContent is LayoutDocument)
                    {
                        LastFocusedDocument = _activeContent;
                    }
                }
            }
        }

Thanks.

May 8, 2012 at 8:33 PM

thank you very much for the issue report, I'll add in it next release

May 9, 2012 at 8:22 AM

I also discovered another hole that should be filled, at least from what I've understand.

In the LayoutDocumentControl, when the "Model" DP turns back to null, its changing does not remove any residual logical children.

I've added a safety flush as follows:

        protected virtual void OnModelChanged(DependencyPropertyChangedEventArgs e)
        {
            //BEGIN MV
            LayoutContent lc;
            lc = e.OldValue as LayoutContent;
            if (lc != null &&
                lc.Content is UIElement)
            {
                var oldLogicalParentPaneControl = LogicalTreeHelper.GetParent(lc.Content as UIElement)
                    as ILogicalChildrenContainer;
                if (oldLogicalParentPaneControl != null)
                    oldLogicalParentPaneControl.InternalRemoveLogicalChild(lc.Content);
            }
            //END MV

            UpdateLogicalParent();
        }

Again, consider it as a discussion, because I'm not sure to have understand correctly the usage of the component.

Cheers