Server-Side UI Automation Provider - WPF Sample

2014-09-14

引用程序集

自动化对等类

WPF Sample

参考

引用程序集


返回

  • UIAutomationProviders.dll
  • UIAutomationTypes.dll
  • WindowsBase.dll

自动化对等类[1]


返回

WPF 控件通过派生自 AutomationPeer 的对等类的树来支持 UI 自动化。  按照约定,对等类的名称须以控件类的名称开头,并以“AutomationPeer”结尾。 例如,ButtonAutomationPeer 是 Button 控件类的对等类。 这些对等类基本等效于 UI 自动化控件类型,但专用于 WPF 元素。 通过 UI 自动化接口访问 WPF 应用程序的自动化代码不直接使用自动化对等类,但同一进程空间中的自动化代码可以直接使用自动化对等类。

图1 ButtonAutomationPeer metadata

WPF Sample[2]


返回

示例代码如下:

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Automation.Peers;
using System.Windows.Automation.Provider;
namespace WpfServerProvider
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
UIAButton btn = new UIAButton();
btn.Content = "TestButton";
this.Content = btn;
}
}
//My WPF button class, derive from WPF Button class
public class UIAButton : Button
{
//Override this function to return my derived AutomationPeer class
protected override AutomationPeer OnCreateAutomationPeer()
{
return new UIAButtonAutomationPeer(this);
}
}
//My AutomationPeer class
//Add implementation of UI ValuePattern comparing with base implementation
public class UIAButtonAutomationPeer : ButtonAutomationPeer, IValueProvider
{
//owner parameter is the WPF Button instance
public UIAButtonAutomationPeer(Button owner)
: base(owner)
{
}
//Return UIA Name property
protected override string GetNameCore()
{
string originalName = base.GetNameCore();
return string.Format("{0} {1}", originalName, DateTime.Now.ToLongTimeString());
}
//Return ValuePattern interface
public override object GetPattern(PatternInterface patternInterface)
{
if (patternInterface == PatternInterface.Value)
{
return this;
}
return null;
}
public bool IsReadOnly { get { return true; } }
//ValuePattern's implementation
public string Value
{
get
{
return string.Format("Height={0},Wideth={1}",
Owner.RenderSize.Height, Owner.RenderSize.Width);
}
}
public void SetValue(string value) { }
}
}

图2 UISpy to WPF provider sample

参考

[1] WPF 自定义控件的 UI 自动化
[2] UI Automation -- Under the Hood

Server-Side UI Automation Provider - WPF Sample的更多相关文章

  1. Client-Side UI Automation Provider - WinForm Sample

    Client-Side UI Automation Provider -  WinForm Sample 2014-09-15 源代码 目录 引用程序集实现提供程序接口分发客户端提供程序注册和配置客户 ...

  2. Server-Side UI Automation Provider - WinForm Sample

    Server-Side UI Automation Provider - WinForm Sample 2014-09-14 源代码  目录 引用程序集提供程序接口公开服务器端 UI 自动化提供程序从 ...

  3. MS UI Automation Introduction

    MS UI Automation Introduction 2014-09-17 MS UI Automation是什么 UIA架构 UI自动化模型 UI自动化树概述 UI自动化控件模式概述 UI 自 ...

  4. 开源自己用python封装的一个Windows GUI(UI Automation)自动化工具,支持MFC,Windows Forms,WPF,Metro,Qt

    首先,大家可以看下这个链接 Windows GUI自动化测试技术的比较和展望 . 这篇文章介绍了Windows中GUI自动化的三种技术:Windows API, MSAA - Microsoft Ac ...

  5. 使用UI Automation实现自动化测试--1-4

    Introduction UI Automation是Microsoft .NET 3.0框架下提供的一种用于自动化测试的技术,是在MSAA基础上建立的,MSAA就是Microsoft Active ...

  6. UI Automation 简介

    转载,源地址: http://blog.csdn.net/ffeiffei/article/details/6637418 MS UI Automation(Microsoft User Interf ...

  7. MS UI Automation简介

    转自:http://blog.csdn.net/ffeiffei/article/details/6637418 MS UI Automation(Microsoft User Interface A ...

  8. 使用UI Automation实现自动化测试 --工具使用

    当前项目进行三个多月了,好久也没有写日志了:空下点时间,补写下N久没写的日志 介绍下两个工具 我本人正常使用的UISpy.exe工具和inspect.exe工具 这是UISPY工具使用的图,正常使用到 ...

  9. UI Automation的两个成熟的框架(QTP 和Selenium)

    自己在google code中开源了自己一直以来做的两个自动化的框架,一个是针对QTP的一个是针对Selenium的,显而易见,一个是商业的UI automation工具,一个是开源的自动化工具. 只 ...

随机推荐

  1. short-path problem (Floyd) 分类: ACM TYPE 2014-09-01 23:58 100人阅读 评论(0) 收藏

    #include <cstdio> #include <iostream> #include <cstring> using namespace std; cons ...

  2. [原] blade中C++ singleton的实现

    最近看了龚大大KalyGE中的singleton, 觉得非常不错(C++中线程安全并且高效的singleton). 可惜blade的代码都是C++03的, 没有使用C++11的任何特性. 笔者对于si ...

  3. [nowCoder] 二进制中1的个数

    题目描述 输入一个整数,输出该数二进制表示中1的个数.其中负数用补码表示.     class Solution { public: int NumberOf1(int n) { ; while(n) ...

  4. 已有a,b两个链表,每个链表中的结点包括学号、成绩。要求把两个链表合并,按学号升序排列

    1.我的思路先将b链表连接在a链表的后面,这个很容易实现,将a链表最后的结点中的p.next改为指向b链表的头结点即可. 再将这个新链表用选择排序即可. 代码如下: #include<stdio ...

  5. Topcoder SRM 630div 2

    A:不断的消除两个相邻的相等字符,简单题. 真心不习惯STL.. #include<iostream> #include <string> #include <vecto ...

  6. jquery 插件开发及extend

    以下信息是在看了IBM上的一篇文章(使用 jQuery(中级),第 2 部分: 创建自己的插件)http://www.ibm.com/developerworks/cn/web/wa-aj-jquer ...

  7. 使用行为树(Behavior Tree)实现网游奖励掉落系统

    原地址:http://blog.csdn.net/akara/article/details/6165421 [原创]使用行为树(Behavior Tree)实现网游奖励掉落系统by AKara 20 ...

  8. 将HTMLCollection/NodeList/伪数组转换成数组

    这里把符合以下条件的对象称为伪数组(ArrayLike) 1,具有length属性 2,按索引方式存储数据 3,不具有数组的push,pop等方法 如 1,function内的arguments . ...

  9. Razor语法学习

    原文:http://www.cnblogs.com/youring2/archive/2011/07/24/2115254.html 1.Razor的文件类型 Razor支持两种文件类型,分别是.cs ...

  10. javascript笔记 面向对象

    Javascript是一种面向对象的弱语言,既然有面向对象,就有继承 继承: 1.call函数和apply函数:区别在于它们参数上的不同,固定参数的用call,可变参数的用apply.换句话说,就是a ...