예제 #1
0
        public virtual TreeItem Construct(object target, TreeItem?parent)
        {
            TreeItem treeItem;

            switch (target)
            {
            case AutomationPeer automationPeer:
                treeItem = new AutomationPeerTreeItem(automationPeer, parent, this);
                break;

            case ResourceDictionary resourceDictionary:
                treeItem = new ResourceDictionaryTreeItem(resourceDictionary, parent, this);
                break;

            case Application application:
                treeItem = new ApplicationTreeItem(application, parent, this);
                break;

            case Window window:
                treeItem = new WindowTreeItem(window, parent, this);
                break;

            case Popup popup:
                treeItem = new PopupTreeItem(popup, parent, this);
                break;

            case DependencyObject dependencyObject:
                treeItem = new DependencyObjectTreeItem(dependencyObject, parent, this);
                break;

            default:
                treeItem = new TreeItem(target, parent, this);
                break;
            }

            treeItem.Reload();

            if (parent is null)
            {
                foreach (var child in treeItem.Children)
                {
                    if (child is ResourceDictionaryTreeItem)
                    {
                        continue;
                    }

                    child.ExpandTo();
                }
            }

            return(treeItem);
        }
예제 #2
0
        protected override void ReloadCore()
        {
            var order = 0;

            foreach (var mergedDictionary in this.dictionary.MergedDictionaries)
            {
                var resourceDictionaryItem = new ResourceDictionaryTreeItem(mergedDictionary, this, this.TreeService)
                {
                    SortOrder = order
                };
                resourceDictionaryItem.Reload();

                this.Children.Add(resourceDictionaryItem);

                ++order;
            }

            foreach (var key in this.dictionary.Keys)
            {
                object target;
                try
                {
                    target = this.dictionary[key];
                }
                catch (XamlParseException)
                {
                    // sometimes you can get a XamlParseException ... because the xaml you are Snoop(ing) is bad.
                    // e.g. I got this once when I was Snoop(ing) some xaml that was referring to an image resource that was no longer there.
                    // in this case, just continue to the next resource in the dictionary.
                    continue;
                }

                if (target == null)
                {
                    // you only get a XamlParseException once. the next time through target just comes back null.
                    // in this case, just continue to the next resource in the dictionary (as before).
                    continue;
                }

                this.Children.Add(new ResourceItem(target, key, this, this.TreeService));
            }
        }