1 //----------------------------------------------------------------
2 // <copyright company="Microsoft Corporation">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //----------------------------------------------------------------
7 namespace System.Activities.Presentation.View.TreeView
10 using System.Activities.Presentation.Internal.PropertyEditing;
11 using System.Activities.Presentation.Model;
12 using System.Activities.Presentation.View.OutlineView;
15 internal sealed class TreeViewItemModelPropertyViewModel : TreeViewItemViewModel<ModelProperty>
17 public TreeViewItemModelPropertyViewModel(TreeViewItemViewModel parent, ModelProperty property)
20 Fx.Assert(property != null, "property cannot be null");
21 this.Value = property;
22 this.VisualValue = property;
23 if (property != null && property.Parent != null)
25 this.GetTracker(property);
31 this.InternalChildren.Add(TreeViewItemViewModel.DummyNode);
35 internal override ChangeNotificationTracker GetTracker(ModelProperty modelProperty, bool createNew)
37 ChangeNotificationTracker tracker = base.GetTracker(modelProperty, createNew);
40 Fx.Assert(this.Value == modelProperty, "The modelProperty should be the same as this.Value.");
41 tracker.Add(modelProperty.Parent, modelProperty);
42 ShowInOutlineViewAttribute viewVisible = ExtensibilityAccessor.GetAttribute<ShowInOutlineViewAttribute>(modelProperty);
43 if (viewVisible != null && !string.IsNullOrWhiteSpace(viewVisible.PromotedProperty))
45 ModelProperty promotedProperty = modelProperty.Value.Properties.Find(viewVisible.PromotedProperty);
46 tracker.Add(promotedProperty.Parent, promotedProperty);
53 internal override void UpdateChildren(ChangeNotificationTracker tracker, EventArgs e)
55 if (this.PerfEventProvider != null)
57 this.PerfEventProvider.DesignerTreeViewUpdateStart();
61 base.UpdateChildren(tracker, e);
63 this.InternalChildren.Clear();
67 if (this.PerfEventProvider != null)
69 this.PerfEventProvider.DesignerTreeViewUpdateEnd();
73 internal override void LoadChildren()
75 if (this.PerfEventProvider != null)
77 this.PerfEventProvider.DesignerTreeViewLoadChildrenStart();
82 if (this.Value.IsCollection)
84 ModelItemCollection mc = this.Value.Value as ModelItemCollection;
85 TreeViewItemViewModel.AddModelItemCollection(this, mc, this.Value);
87 else if (this.Value.IsDictionary)
89 ModelItemDictionary dictionary = this.Value.Dictionary;
90 TreeViewItemViewModel.AddModelItemDictionary(this, dictionary, this.Value);
92 else if (this.Value.Value != null)
94 TreeViewItemViewModel.AddChild(this, this.Value.Value, this.Value.Value, this.DuplicatedNodeVisible, string.Empty, this.Value);
97 if (this.PerfEventProvider != null)
99 this.PerfEventProvider.DesignerTreeViewLoadChildrenEnd();
103 internal override void UpdateState()
105 if (this.Value.Value != null || (this.Value.IsCollection && this.Value.Collection.Count > 0) ||
106 (this.Value.IsDictionary && this.Value.Dictionary.Count > 0))
108 this.State = TreeViewItemState.HasChildren;
114 protected override EditingContext GetEditingContext()
116 if (this.Value != null && this.Value.Parent != null)
118 return this.Value.Parent.GetEditingContext();
122 return base.GetEditingContext();