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. 异步HTTP请求

    一.自定义异步的HTTP请求 1.自定义一个AsyncHttpClient类,用于处理HTTP请求,实际原理就是新开启一个线程,调用HttpClient处理GET和POST请求 package com ...

  2. Linux查看日志命令

    tail -f /var/log/apport.log more /var/log/xorg.0.log cat /var/log/mysql.err less /var/log/messages g ...

  3. [转]日期格式化(yyyy-MM-dd)中,为什么 M 多大写?

    最近犯了个可傻逼的错误,格式化年月日的时候不小心将yyyy-MM-dd写成YYYY-MM-dd,导致格式化结果中年不正确. 看看知乎上的说法 问题: http://www.zhihu.com/ques ...

  4. c#实现串口操作 SerialPort

    命名空间:using System.IO.Ports;该类提供了同步 I/O 和事件驱动的 I/O.对管脚和中断状态的访问以及对串行驱动程序属性的访问. 操作类声明: SerialPort sp = ...

  5. 如何使用 OneAPM 监控微软 Azure Cloud Service ?

    不知不觉微软 Azure 已经进入中国市场近两年的时间.那么 Azure 平台的性能究竟如何?资源加载的延迟.虚拟机的稳定性等问题是否切实满足客户期许.这些都是大家对微软 Azure 这个国外的云服务 ...

  6. 最长连续回文串(最优线性时间O(n))

    转自:http://blog.csdn.net/hopeztm/article/details/7932245 Given a string S, find the longest palindrom ...

  7. POJ 1969

    #include <iostream> #include <cmath> using namespace std; int main() { //freopen("a ...

  8. HDU 2602 Bone Collector (简单01背包)

    Bone Collector http://acm.hdu.edu.cn/showproblem.php?pid=2602 Problem Description Many years ago , i ...

  9. 历代诗词咏宁夏注释2_----苍岩道人<登文昌阁>

    登文昌阁[1] 苍岩道人 壮年碌碌走尘埃,此地清幽不肯来. 老去始惊春梦促,韶光易过槿花开.[2] 历朝兴废书千卷,万古忠奸土一堆.[3] 惟爱莎罗歌最好,闲时拍板满斟杯.[4] 注释 [说明]选自& ...

  10. C# 与C/C++相互调用

    C++调用C#的DLLhttp://www.csharpwin.com/csharpspace/11385r8940.shtml C#调用C/C++动态库必须注意的几个问题http://www.rob ...