I have used the "System.Windows.Automation.AutomationElement" class to interact with other applications. Different applications organize components in different ways, but if you are interacting with your own application, traversing these elements to find the correct one should be fairly easy...
Here is some code that i use, to invoke the click() "invokepattern" on a menuItem in a different application. This method assumes that the menuItems are located in the Window. Some applications may place the menu in a pane, or maybe elsewhere.
private void clickMenuItem(string windowTitle, string menu, string menuItem)
{
AutomationElement root = AutomationElement.RootElement;
foreach (AutomationElement window in root.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window)))
{
if (window.Current.Name.Contains(windowTitle) && window.Current.IsKeyboardFocusable)
{
AutomationElement menuAutomationElement = window.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Menu));
PropertyCondition nameCond = new PropertyCondition(AutomationElement.NameProperty, menu);
AutomationElement selectedMenu = menuAutomationElement.FindFirst(TreeScope.Descendants, nameCond);
ExpandCollapsePattern fileECPat = selectedMenu.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;
fileECPat.Expand();
nameCond = new PropertyCondition(AutomationElement.NameProperty, menuItem);
AutomationElement selectedMenuItem = selectedMenu.FindFirst(TreeScope.Descendants, nameCond);
InvokePattern closeInvPat = selectedMenuItem.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
closeInvPat.Invoke();
}
}
}