title: set text on textfield / textbox with the automation framework and get the change event
body: <p>I want to set a text on a textfield / textbox element with the Mircosoft <strong>UI Automation</strong> framework, that means on a <code>AutomationElement</code> from the <code>ControlType.Edit</code> or <code>ControlType.Document</code>.</p>
  
  <p>At the moment i'm using the <code>TextPattern</code> to get the text from one of these <code>AutomationElements</code>:</p>
  
  <pre><code>TextPattern tp = (TextPattern)element.GetCurrentPattern(TextPattern.Pattern);
  string text = tp.DocumentRange.GetText(-1).Trim();
  </code></pre>
  
  <p>But now I want to set a new text in the <code>AutomationElement</code>. I can't find a method for this in the <code>TextPattern</code> class. So I'm trying to use the <code>ValuePattern</code> but I'm not sure if that's the right way to do it:</p>
  
  <pre><code>ValuePattern value = element.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
  value.SetValue(insertText);
  </code></pre>
  
  <p>Is there an other way to set the text value?</p>
  
  <p>An other question is how can I get an event when the text was changed on a <code>Edit</code> / <code>Document</code> element? I tried to use the <code>TextChangedEvent</code> but i don't get any events fired when changing the text:</p>
  
  <pre><code>AutomationEventHandler ehTextChanged = new AutomationEventHandler(text_event);
  Automation.AddAutomationEventHandler(TextPattern.TextChangedEvent, element, TreeScope.Element, ehTextChanged);
  
  private void text_event(object sender, AutomationEventArgs e)
  {
      Console.WriteLine("Text changed");
  }
  </code></pre>