title: No InvokeEvent fired from button ( MS UI Automation Framework )
body: <p>I have a little application with a flowlayout ( contains a second flowlayout with a few components and beside the second flowlayout a single close button ).</p>
  
  <p>Here a Screen from Spy++: <a href="http://i.stack.imgur.com/0UKy0.png" rel="nofollow">http://i.stack.imgur.com/0UKy0.png</a></p>
  
  <p>Yet i want to add a EventHandler to check the Invoke from the Close Button (last one in the screenshot). But i don't get any events from the button and i have no clue why...</p>
  
  <p>Code to start and find the application: </p>
  
  <pre><code>Process p = Process.Start("..\\..\\..\\CSharpCaA\\bin\\Release\\dotnetCaA.exe");
  AutomationElement form = AutomationElement.FromHandle(p.MainWindowHandle);
  </code></pre>
  
  <p>After i got the right Form i´m going to search for the close button:</p>
  
  <pre><code>AutomationElement close = form.FindFirst(TreeScope.Descendants,
  new PropertyCondition(AutomationElement.AutomationIdProperty, "close"));
  </code></pre>
  
  <p>to this point everything is fine, i have the right form and the right button ( i testet both ), so i'm going to add the EventHandler for the InvokeEvent:</p>
  
  <pre><code>Automation.AddAutomationEventHandler(InvokePattern.InvokedEvent, close,
  TreeScope.Element, new AutomationEventHandler(close_event));
  </code></pre>
  
  <p>My close_event method:</p>
  
  <pre><code>    private void close_event(object sender, AutomationEventArgs e)
      {
          AutomationElement senderElement = sender as AutomationElement;
          // a console writeline and other stuff            
      }
  </code></pre>
  
  <p>So I'm going to click the button and...nothing happens ! No Event fired from the close button and my close_event method wasn't called.</p>
  
  <p>Somebody a idea why ? And first i thought something is wrong with my close_event but if i write something like this: </p>
  
  <pre><code>     Automation.AddAutomationEventHandler(InvokePattern.InvokedEvent,
       AutomationElement.RootElement, TreeScope.Descendants, close_event);
  </code></pre>
  
  <p>i'm getting events, but from the forms and not from the components.
  i tried everything, to start the form in a new thread, to create the Eventhandler in a new thread bot nothing helped. and i don't see a reason why it is not working. </p>
  
  <p><strong>Any ideas ?</strong></p>
  
  <p>thanks</p>