1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
4 namespace System.Activities.Presentation.Internal.PropertyEditing.Automation
7 using System.Collections;
8 using System.Collections.Generic;
9 using System.ComponentModel;
12 using System.Windows.Automation;
13 using System.Windows.Automation.Peers;
14 using System.Windows.Automation.Provider;
15 using System.Windows.Controls;
16 using System.Windows.Media;
18 using System.Activities.Presentation;
19 using System.Activities.Presentation.PropertyEditing;
21 using System.Activities.Presentation.Internal.PropertyEditing.FromExpression.Framework.PropertyInspector;
22 using System.Activities.Presentation.Internal.PropertyEditing.Selection;
25 // AutomationPeer for PropertyContainer
27 internal class PropertyContainerAutomationPeer : UIElementAutomationPeer, IValueProvider, IScrollItemProvider, IAutomationFocusChangedEventSource
30 private PropertyContainer _container;
35 // <param name="container"></param>
36 public PropertyContainerAutomationPeer(PropertyContainer container)
39 if (container == null)
41 throw FxTrace.Exception.ArgumentNull("container");
44 _container = container;
48 // Gets a value indicating whether the contained PropertyContainer is read-only
50 public bool IsReadOnly
52 get { return _container.PropertyEntry.IsReadOnly || !_container.PropertyEntry.PropertyValue.CanConvertFromString; }
56 // Gets the value of the property within the PropertyContainer
60 get { return _container.PropertyEntry.PropertyValue.StringValue; }
64 // IScrollItemProvider Members
67 // This public method is called when parent creates the CategoryContainerItemAutomationPeer
68 // in the GetChildrenCore, thus listening to the changes in the IsSelectedProperty.
70 internal void AddFocusEvents()
72 if (_container != null)
74 HookUpFocusEvents(_container, OnIsSelectedValueChanged);
79 // "PropertyContainer"
81 // <returns>"PropertyContainer"</returns>
82 protected override string GetClassNameCore()
84 return typeof(PropertyContainer).Name;
88 // Returns the name of the contained property
90 // <returns></returns>
91 protected override string GetNameCore()
93 return _container.PropertyEntry == null ? string.Empty : _container.PropertyEntry.DisplayName;
97 // Currently supported patterns: Value
99 // <param name="patternInterface"></param>
100 // <returns></returns>
101 public override object GetPattern(PatternInterface patternInterface)
103 if (patternInterface == PatternInterface.Value)
107 else if (patternInterface == PatternInterface.ScrollItem)
112 return base.GetPattern(patternInterface);
116 // Private helper function to listen to the changes in the IsSelectedProperty,
117 // which then fires the OnValueChanged event.
119 // <param name="expander">Expander control</param>
120 // <param name="valueChangedEvent">ValueChanged event</param>
121 private static void HookUpFocusEvents(PropertyContainer container, EventHandler valueChangedEvent)
123 if (container != null)
125 DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(PropertySelection.IsSelectedProperty, typeof(PropertyContainer));
128 dpd.AddValueChanged(container, valueChangedEvent);
134 // The actual event handler, that fires when the IsSelected DP changes.
135 // Here we raise the AutomationFocus event for the
136 // Advanced (More Properties) properties expander.
138 // <param name="sender">Expander</param>
139 // <param name="e">EventArgs</param>
140 private void OnIsSelectedValueChanged(object sender, EventArgs e)
142 // Add logic to respond to "Selection"
143 bool curVal = PropertySelection.GetIsSelected(sender as DependencyObject);
146 this.RaiseAutomationEvent(AutomationEvents.AutomationFocusChanged);
151 // This public method is called when parent creates the CategoryContainerItemAutomationPeer
152 // in the GetChildrenCore, thus clearing off all the event listeners before we add new ones
154 public void RemoveFocusEvents()
156 if (_container != null)
158 UnHookFocusEvents(_container, OnIsSelectedValueChanged);
163 // Private method to unhook the ValueChanged event.
165 // <param name="expander">Expander</param>
166 // <param name="valueChangedEvent">ValueChanged event</param>
167 private static void UnHookFocusEvents(PropertyContainer container, EventHandler valueChangedEvent)
169 if (container != null)
171 DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(PropertySelection.IsSelectedProperty, typeof(PropertyContainer));
174 dpd.RemoveValueChanged(container, valueChangedEvent);
179 // IValueProvider Members
182 // Sets the value of the property within the PropertyContainer
184 // <param name="value">Value to set</param>
185 public void SetValue(string value)
187 _container.PropertyEntry.PropertyValue.StringValue = value;
191 // Scrolls the contained PropertyContainer into view, if it's within a scrolling control
193 public void ScrollIntoView()
195 _container.BringIntoView();
199 // IAutomationFocusChangedEventSource Members
200 public void UnloadEventHook()