c# - WPF在按钮上播放 “Click”动画。模拟代码点击

标签 c# .net wpf mvvm wpf-controls

我有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/

相关文章:

c# - HTML文本分析

c# - 编辑 Resources.resx 文件时,Resources.Designer.cs 无法更新,因为 TFS 未将其 checkout

c# - 如何根据属性值启用或禁用复选框?

c# - 如何在 DataGrid 的行中绑定(bind)多个数据来显示工具提示?

c# - 引发类型实现接口(interface)的对象的事件

c# - MahApps Metro 和 DataGridExtensions

c# - 如何格式化未在 C# MVC 中初始化的小数?

c# - 如何用 C#(或 VB.NET)编写 WinMerge 插件

c# - 如何让我的按钮在 Unity 中使用 C# 做不同的事情?

.net - 如何替换标准 DataAnnotations 错误消息