我有10个默认WPF按钮。
在某些特定情况下,我必须模拟/播放 View 模型中单击按钮的动画。 (演示模式下的应用程序,并向用户演示其工作方式。)
我不知道如何模仿默认的按钮单击,有什么想法吗?
最佳答案
您将需要UI自动化框架(System.Windows.Automation)才能通过代码单击按钮。
var element = AutomationElement.RootElement.FindFirst(
TreeScope.Descendants,
new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Start", PropertyConditionFlags.IgnoreCase))
);
var pattern = (InvokePattern)element.GetCurrentPattern(InvokePattern.Pattern);
pattern.Invoke();
此代码将单击WPF应用程序的Windows开始按钮。您可以以相同的方式在应用程序中搜索按钮。
所需引用:UIAutomationClient,UIAutomationTypes
关于c# - WPF在按钮上播放 “Click”动画。模拟代码点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17744529/