Server-Side UI Automation Provider - WPF Sample
Server-Side UI Automation Provider - WPF Sample
2014-09-14
引用程序集
- 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的更多相关文章
- Client-Side UI Automation Provider - WinForm Sample
Client-Side UI Automation Provider - WinForm Sample 2014-09-15 源代码 目录 引用程序集实现提供程序接口分发客户端提供程序注册和配置客户 ...
- Server-Side UI Automation Provider - WinForm Sample
Server-Side UI Automation Provider - WinForm Sample 2014-09-14 源代码 目录 引用程序集提供程序接口公开服务器端 UI 自动化提供程序从 ...
- MS UI Automation Introduction
MS UI Automation Introduction 2014-09-17 MS UI Automation是什么 UIA架构 UI自动化模型 UI自动化树概述 UI自动化控件模式概述 UI 自 ...
- 开源自己用python封装的一个Windows GUI(UI Automation)自动化工具,支持MFC,Windows Forms,WPF,Metro,Qt
首先,大家可以看下这个链接 Windows GUI自动化测试技术的比较和展望 . 这篇文章介绍了Windows中GUI自动化的三种技术:Windows API, MSAA - Microsoft Ac ...
- 使用UI Automation实现自动化测试--1-4
Introduction UI Automation是Microsoft .NET 3.0框架下提供的一种用于自动化测试的技术,是在MSAA基础上建立的,MSAA就是Microsoft Active ...
- UI Automation 简介
转载,源地址: http://blog.csdn.net/ffeiffei/article/details/6637418 MS UI Automation(Microsoft User Interf ...
- MS UI Automation简介
转自:http://blog.csdn.net/ffeiffei/article/details/6637418 MS UI Automation(Microsoft User Interface A ...
- 使用UI Automation实现自动化测试 --工具使用
当前项目进行三个多月了,好久也没有写日志了:空下点时间,补写下N久没写的日志 介绍下两个工具 我本人正常使用的UISpy.exe工具和inspect.exe工具 这是UISPY工具使用的图,正常使用到 ...
- UI Automation的两个成熟的框架(QTP 和Selenium)
自己在google code中开源了自己一直以来做的两个自动化的框架,一个是针对QTP的一个是针对Selenium的,显而易见,一个是商业的UI automation工具,一个是开源的自动化工具. 只 ...
随机推荐
- Matlab动态数组实现
clear all; clc; a = []; %不是null,也不能什么都不是 for i=1:10 a = [a i]; end
- 异步HTTP请求
一.自定义异步的HTTP请求 1.自定义一个AsyncHttpClient类,用于处理HTTP请求,实际原理就是新开启一个线程,调用HttpClient处理GET和POST请求 package com ...
- NYOJ-244 16进制的简单运算 AC 分类: NYOJ 2014-01-17 21:11 195人阅读 评论(0) 收藏
#include<stdio.h> int main() { long x,y; char op; int t; scanf("%d ", &t); while ...
- 常用的Python字符串常量
下面是一些常用的Python字符串常量string.digits:包含0-9的字符串string.letters:包含所有大小写字母的字符串 string.lowercase:所有小写字母string ...
- PowerDesigner(五)-概念数据模型(CDM生成LDM,PDM和OOM)(转)
概念数据模型 概念数据模型(Conceptual Data Model,CDM):表达的是数据整体逻辑结构,该结构独立于任何软件和数据存储结构,即它只是系统分析人员,应用程序设计人员,维护人员和用户之 ...
- Codeforces Round #216 (Div. 2)解题报告
又范低级错误! 只做了两题!一道还被HACK了,囧! A:看了很久!应该是到语文题: 代码:#include<iostream> #include<]; ,m2=; ;i ...
- 深入理解javacript之prototype
对于javascript这样一种前端语言,个人觉得,要真正的理解其oop, 就必须要彻底搞清楚javascript的对象,原型链,作用域,闭包,以及this所引用的对象等概念.这些对弄明白了,应该就可 ...
- Activity学习(五)——Bundle机制
上一篇文章我简单介绍了Activity之间简单切换,很简单,这一篇文章我们继续聊Android中程序页面互相跳转的Activity,不过这一次我们在Activity跳转时,携带一些简单的数据,然后在新 ...
- Visual Studio 常用快捷键 (二)
想不到上一篇 [Visual Studio 常用快捷键] 受这么多人的欢迎.看来大家对Visual Studio的用法非常感兴趣. 接下来我准备写一个 “Visual Studio使用技巧 ” 一个系 ...
- linux下文件编码的查看与修改
在Linux中查看文件编码可以通过vim编辑器来查看,在vim命令模式下输入如下命令即可: :set fileencoding //在vim中查看文件编码 如果你只是想查看其它编码格式的文件或者想解决 ...