1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
4 namespace System.Activities.Presentation.Internal.PropertyEditing.Automation
7 using System.Collections.Generic;
9 using System.Windows.Automation;
10 using System.Windows.Automation.Peers;
11 using System.Windows.Automation.Provider;
12 using System.Windows.Controls;
13 using System.Windows.Media;
15 using System.Activities.Presentation.PropertyEditing;
16 using System.Activities.Presentation.Internal.PropertyEditing.FromExpression.Framework.ValueEditors;
18 using System.Activities.Presentation.Internal.PropertyEditing.Editors;
19 using System.Activities.Presentation.Internal.Properties;
22 // AutomationPeer for the SubPropertyEditor
24 internal class SubPropertyEditorAutomationPeer : UIElementAutomationPeer, IExpandCollapseProvider
27 private SubPropertyEditor _editor;
28 List<AutomationPeer> _children;
30 public SubPropertyEditorAutomationPeer(SubPropertyEditor editor)
35 // Hook into the VisualsChanged event so that this peer can invalidate
36 // itself appropriately
39 editor.VisualsChanged += new EventHandler(OnEditorVisualsChanged);
42 _children = new List<AutomationPeer>();
47 // Gets the ExpandCollapse state of the sub-properties
49 public ExpandCollapseState ExpandCollapseState
52 return _editor.IsExpanded ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed;
57 protected override string GetNameCore()
59 return Resources.PropertyEditing_SubPropertyEditorAutomationName;
62 protected override string GetClassNameCore()
64 return typeof(SubPropertyEditor).Name;
67 // Support the ExpandCollapse pattern
68 public override object GetPattern(PatternInterface patternInterface)
70 if (patternInterface == PatternInterface.ExpandCollapse)
75 return base.GetPattern(patternInterface);
78 protected override List<AutomationPeer> GetChildrenCore()
80 if (_children != null)
82 foreach (AutomationPeer peer in _children)
84 IAutomationFocusChangedEventSource unhookEventPeer = peer as IAutomationFocusChangedEventSource;
85 if (unhookEventPeer != null)
87 unhookEventPeer.UnloadEventHook();
93 // See if we have access to the QuickTypes combo box (it may or may not be available)
94 AutomatedChoiceEditor choiceEditor = VisualTreeUtils.GetNamedChild<AutomatedChoiceEditor>(_editor, "PART_ValueEditor");
96 // If we do, present it as one of our children
97 if (choiceEditor != null)
99 _children.Add(new HiddenUIElementAutomationPeer(choiceEditor));
102 // Add any sub-properties
103 ItemsControl properties = VisualTreeUtils.GetNamedChild<ItemsControl>(_editor, "PART_SubPropertyList");
105 if (properties != null)
107 int childCount = properties.Items.Count;
109 for (int i = 0; i < childCount; i++)
111 PropertyContainer propertyContainer = properties.ItemContainerGenerator.ContainerFromIndex(i) as PropertyContainer;
113 if (propertyContainer != null)
115 PropertyContainerAutomationPeer peer = new PropertyContainerAutomationPeer(propertyContainer);
125 private void OnEditorVisualsChanged(object sender, EventArgs e)
127 this.InvalidatePeer();
130 // IExpandCollapseProvider Members
133 // Attempts to collapse the sub-properties
135 public void Collapse()
139 _editor.IsExpanded = false;
144 // Attempts to expand the sub-properties
148 if (_editor != null &&
149 _editor.PropertyEntry != null &&
150 _editor.PropertyEntry.PropertyValue.HasSubProperties == true)
152 _editor.IsExpanded = true;