コード例 #1
0
        internal static TreeViewItemViewModel Expand(TreeViewItemModelItemViewModel rootTreeViewItem, ModelItem modelItemToExpandTo)
        {
            Fx.Assert(modelItemToExpandTo != null && rootTreeViewItem != null, "rootTreeViewItem and modelItemToExpand should not have null value");

            // ModelItems with HidePropertyInOutlineViewAttribute are invisible in the designerTree.
            if (ExtensibilityAccessor.GetAttribute<HidePropertyInOutlineViewAttribute>(modelItemToExpandTo) != null)
            {
                return null;
            }

            Stack pathStack = new Stack();

            TreeViewItemViewModel itemToBeSelected = null;

            if (GetExpandingPath(modelItemToExpandTo, pathStack, new HashSet<ModelItem>()))
            {
                // If the root of modelItemToExpandTo differs from the root of the designerTree, it means modelItemToExpandTo doesn't belong to the designerTree.
                if (pathStack.Pop() != rootTreeViewItem.VisualValue)
                {
                    return null;
                }

                object item = null;
                TreeViewItemViewModel treeViewItem = rootTreeViewItem;
                TreeViewItemViewModel tempTreeViewItem = rootTreeViewItem;

                // Using the path to the root, expand the corresponding tree node. Ignore the items which is not visible on the designerTree.
                while (pathStack.Count > 0)
                {
                    if (tempTreeViewItem != null)
                    {
                        treeViewItem = tempTreeViewItem;
                        treeViewItem.IsExpanded = true;
                    }

                    item = pathStack.Pop();
                    tempTreeViewItem = (from child in treeViewItem.Children
                                        where (child is TreeViewItemModelItemViewModel && ((TreeViewItemModelItemViewModel)child).VisualValue == item as ModelItem)
                                        || (child is TreeViewItemModelPropertyViewModel && ((TreeViewItemModelPropertyViewModel)child).VisualValue == item as ModelProperty)
                                        || (child is TreeViewItemKeyValuePairModelItemViewModel && ((TreeViewItemKeyValuePairModelItemViewModel)child).VisualValue.Value == item as ModelItem)
                                        select child).FirstOrDefault();

                    // For TreeViewItemKeyValuePairModelItemViewModel, its path to the children is very complicated.
                    // Take Switch as example: Switch(ModelItem) -> Cases(ModelProperty) -> KeyDictionaryCollection(ModelItem) -> ItemsCollection(ModelProperty) -> ModelItemKeyValuePair<T, Activity>(ModelItem) -> Value(ModelProperty) -> Children
                    // All the path nodes except Switch and Children are invisible and can be ignored, the child node in the path is used twice to search for TreeViewItemKeyValuePairModelItemViewModel and its children in designerTree.
                    if (tempTreeViewItem is TreeViewItemKeyValuePairModelItemViewModel)
                    {
                        // For further searching
                        pathStack.Push(item);
                    }

                    if (pathStack.Count == 0)
                    {
                        itemToBeSelected = tempTreeViewItem;
                    }
                }
            }

            return itemToBeSelected;
        }
コード例 #2
0
        public void SetRootDesigner(ModelItem modelItem)
        {
            rootModelItemViewModel = new TreeViewItemModelItemViewModel(null, modelItem);
            this.ItemsSource = new ObservableCollection<TreeViewItemModelItemViewModel>() { rootModelItemViewModel };

            if (!isSelectionSubscribed)
            {
                Selection.Subscribe(Context, ModelItemSelectionChanged);
                isSelectionSubscribed = true;
            }
        }
コード例 #3
0
 internal static TreeViewItemViewModel CreateViewModel(TreeViewItemViewModel parent, object value)
 {
     TreeViewItemViewModel viewModel = null;
     if (typeof(ModelItem).IsAssignableFrom(value.GetType()))
     {
         viewModel = new TreeViewItemModelItemViewModel(parent, value as ModelItem);
     }
     else if (typeof(ModelProperty).IsAssignableFrom(value.GetType()))
     {
         viewModel = new TreeViewItemModelPropertyViewModel(parent, value as ModelProperty);
     }
     else if (typeof(KeyValuePair<ModelItem, ModelItem>).IsAssignableFrom(value.GetType()))
     {
         viewModel = new TreeViewItemKeyValuePairModelItemViewModel(parent, (KeyValuePair<ModelItem, ModelItem>)value);
     }
     return viewModel;
 }