ButtonAutomationPeer bap = new ButtonAutomationPeer(myButton); IInvokeProvider iip = bap.GetPattern(PatternInterface.Invoke) as IInvokeProvider; iip.Invoke(); // This clicks the Button
ButtonAutomationPeer在namespace using System.Windows.Automation.Peers;中
IInvokeProvider须添加引用UIAutomationProvider.dll,并添加namespace using System.Windows.Automation.Provider;
此代码在自动化测试时很有用。
附System.Windows.Automation.Peers下所有类:
namespace System.Windows.Automation.Peers { public class ButtonAutomationPeer : ButtonBaseAutomationPeer, IInvokeProvider public abstract class ButtonBaseAutomationPeer : FrameworkElementAutomationPeer public class CheckBoxAutomationPeer : ToggleButtonAutomationPeer public class ComboBoxAutomationPeer : SelectorAutomationPeer, IValueProvider, IExpandCollapseProvider public abstract class ContentTextAutomationPeer : FrameworkContentElementAutomationPeer public class ContextMenuAutomationPeer : FrameworkElementAutomationPeer public class DocumentAutomationPeer : ContentTextAutomationPeer public class DocumentPageViewAutomationPeer : FrameworkElementAutomationPeer public class DocumentViewerAutomationPeer : DocumentViewerBaseAutomationPeer public class DocumentViewerBaseAutomationPeer : FrameworkElementAutomationPeer public class ExpanderAutomationPeer : FrameworkElementAutomationPeer, IExpandCollapseProvider public class FixedPageAutomationPeer : FrameworkElementAutomationPeer public class FlowDocumentPageViewerAutomationPeer : DocumentViewerBaseAutomationPeer public class FlowDocumentReaderAutomationPeer : FrameworkElementAutomationPeer, IMultipleViewProvider public class FlowDocumentScrollViewerAutomationPeer : FrameworkElementAutomationPeer public class FrameAutomationPeer : FrameworkElementAutomationPeer public class FrameworkContentElementAutomationPeer : ContentElementAutomationPeer public class FrameworkElementAutomationPeer : UIElementAutomationPeer public class GridSplitterAutomationPeer : ThumbAutomationPeer, ITransformProvider public class GridViewAutomationPeer : IViewAutomationPeer, ITableProvider, IGridProvider public class GridViewCellAutomationPeer : FrameworkElementAutomationPeer, ITableItemProvider, IGridItemProvider public class GridViewColumnHeaderAutomationPeer : FrameworkElementAutomationPeer, IInvokeProvider, ITransformProvider public class GridViewHeaderRowPresenterAutomationPeer : FrameworkElementAutomationPeer public class GridViewItemAutomationPeer : ListBoxItemAutomationPeer public class GroupBoxAutomationPeer : FrameworkElementAutomationPeer public class GroupItemAutomationPeer : FrameworkElementAutomationPeer internal class HwndHostAutomationPeer : FrameworkElementAutomationPeer public class HyperlinkAutomationPeer : TextElementAutomationPeer, IInvokeProvider public class ImageAutomationPeer : FrameworkElementAutomationPeer public class InkCanvasAutomationPeer : FrameworkElementAutomationPeer public class InkPresenterAutomationPeer : FrameworkElementAutomationPeer public abstract class ItemAutomationPeer : AutomationPeer [DefaultMember("Item")] internal class ItemPeersStorage public abstract class ItemsControlAutomationPeer : FrameworkElementAutomationPeer public interface IViewAutomationPeer public class LabelAutomationPeer : FrameworkElementAutomationPeer public class ListBoxAutomationPeer : SelectorAutomationPeer public class ListBoxItemAutomationPeer : SelectorItemAutomationPeer, IScrollItemProvider public class ListBoxItemWrapperAutomationPeer : FrameworkElementAutomationPeer public class ListViewAutomationPeer : ListBoxAutomationPeer public class MediaElementAutomationPeer : FrameworkElementAutomationPeer public class MenuAutomationPeer : FrameworkElementAutomationPeer public class MenuItemAutomationPeer : FrameworkElementAutomationPeer, IExpandCollapseProvider, IInvokeProvider, IToggleProvider public class NavigationWindowAutomationPeer : WindowAutomationPeer public class PasswordBoxAutomationPeer : FrameworkElementAutomationPeer, IValueProvider internal class PopupRootAutomationPeer : FrameworkElementAutomationPeer public class ProgressBarAutomationPeer : RangeBaseAutomationPeer, IRangeValueProvider public class RadioButtonAutomationPeer : ToggleButtonAutomationPeer, ISelectionItemProvider public class RangeBaseAutomationPeer : FrameworkElementAutomationPeer, IRangeValueProvider public class RepeatButtonAutomationPeer : ButtonBaseAutomationPeer, IInvokeProvider public class RichTextBoxAutomationPeer : TextAutomationPeer internal class RootBrowserWindowAutomationPeer : WindowAutomationPeer public class ScrollBarAutomationPeer : RangeBaseAutomationPeer public class ScrollViewerAutomationPeer : FrameworkElementAutomationPeer, IScrollProvider public abstract class SelectorAutomationPeer : ItemsControlAutomationPeer, ISelectionProvider public abstract class SelectorItemAutomationPeer : ItemAutomationPeer, ISelectionItemProvider public class SeparatorAutomationPeer : FrameworkElementAutomationPeer public class SliderAutomationPeer : RangeBaseAutomationPeer public class StatusBarAutomationPeer : FrameworkElementAutomationPeer public class StatusBarItemAutomationPeer : FrameworkElementAutomationPeer public class TabControlAutomationPeer : SelectorAutomationPeer, ISelectionProvider public class TabItemAutomationPeer : SelectorItemAutomationPeer, ISelectionItemProvider public class TabItemWrapperAutomationPeer : FrameworkElementAutomationPeer public class TableAutomationPeer : TextElementAutomationPeer, IGridProvider public class TableCellAutomationPeer : TextElementAutomationPeer, IGridItemProvider public abstract class TextAutomationPeer : FrameworkElementAutomationPeer public class TextBlockAutomationPeer : FrameworkElementAutomationPeer public class TextBoxAutomationPeer : TextAutomationPeer, IValueProvider public class TextElementAutomationPeer : ContentTextAutomationPeer public class ThumbAutomationPeer : FrameworkElementAutomationPeer public class ToggleButtonAutomationPeer : ButtonBaseAutomationPeer, IToggleProvider public class ToolBarAutomationPeer : FrameworkElementAutomationPeer public class ToolTipAutomationPeer : FrameworkElementAutomationPeer public class TreeViewAutomationPeer : FrameworkElementAutomationPeer, ISelectionProvider public class TreeViewItemAutomationPeer : FrameworkElementAutomationPeer, IExpandCollapseProvider, ISelectionItemProvider, IScrollItemProvider public class UserControlAutomationPeer : FrameworkElementAutomationPeer public class Viewport3DAutomationPeer : FrameworkElementAutomationPeer public class WindowAutomationPeer : FrameworkElementAutomationPeer }