using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using System.Windows.Automation.Peers; using System.Windows.Automation.Provider; namespace SWASilverlightApp { public partial class BoxAndButton : UserControl, IInvokeProvider, IValueProvider { public BoxAndButton() { InitializeComponent(); } protected override AutomationPeer OnCreateAutomationPeer() { return new BoxAndButtonAutomationPeer(this); } private void SubmitButton_Click(object sender, RoutedEventArgs e) { char[] chars = TextEntryBox.Text.ToCharArray(); Array.Reverse(chars); TextEntryBox.Text = new string(chars); } #region IInvokeProvider Members void IInvokeProvider.Invoke() { AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(SubmitButton); IInvokeProvider invokeProvider = (IInvokeProvider)peer.GetPattern(PatternInterface.Invoke); invokeProvider.Invoke(); } #endregion #region IValueProvider Members bool IValueProvider.IsReadOnly { get { return TextEntryBox.IsReadOnly; } } void IValueProvider.SetValue(string value) { TextEntryBox.Text = value; } string IValueProvider.Value { get { return TextEntryBox.Text; } } #endregion } public class BoxAndButtonAutomationPeer : FrameworkElementAutomationPeer { public BoxAndButtonAutomationPeer(BoxAndButton owner) : base(owner) { } public override object GetPattern(PatternInterface patternInterface) { switch(patternInterface) { case PatternInterface.Value: return Owner; case PatternInterface.Invoke: return Owner; } return base.GetPattern(patternInterface); } //Commented out because its current form makes UISpy go crazy. //protected override List GetChildrenCore() //{ // return new List(); //} } }