/// <summary> /// 执行按钮Click事件 /// </summary> /// <param name="sender"></param> public static void PerformClick(this System.Windows.Controls.Primitives.ButtonBase sender) { //System.Windows.Automation.Peers.ButtonAutomationPeer bam = new System.Windows.Automation.Peers.ButtonAutomationPeer(button); //System.Windows.Automation.Provider.IInvokeProvider iip = bam.GetPattern(System.Windows.Automation.Peers.PatternInterface.Invoke) as System.Windows.Automation.Provider.IInvokeProvider; //iip.Invoke(); sender.RaiseEvent(System.Windows.Controls.Primitives.ButtonBase.ClickEvent); }
public void ClickButton(System.Windows.Controls.Primitives.ButtonBase button) { this.Dispatcher.Invoke((Action)(() => button.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)) )); }