日期:2014-05-17  浏览次数:21357 次

WPF,AutomationProperties类起什么作用的?
AutomationProperties类:MSDN为获取或设置 AutomationPeer 元素实例的相关属性值提供了一种途径。

比如在标准的ScrollViewer控件模板中,出现有以下这个滚动条:

<ScrollBar x:Name="PART_VerticalScrollBar" AutomationProperties.AutomationId="VerticalScrollBar" Cursor="Arrow" Grid.Column="1"
                   Maximum="{TemplateBinding ScrollableHeight}" Minimum="0" Grid.Row="0" Visibility="{TemplateBinding
                  ComputedVerticalScrollBarVisibility}" Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" 
                   ViewportSize="{TemplateBinding ViewportHeight}"/>


这里面的AutomationProperties.AutomationId="VerticalScrollBar"怎么理解呢?

------解决方案--------------------
AutomationPeer是自动化UI测试框架相关的
http://www.marcwils.be.eu.org/posts/implementing-a-ui-automationpeer-for-your-wpf-custom-control
可以看看这篇文章,也有demo下载
------解决方案--------------------
这些应该是属于UI自动化的知识,你查找下吧
------解决方案--------------------
嗯,UI Automation。UI Automation允许程序模拟人工去操作一个用户界面来执行程序。
------解决方案--------------------
你这段代码我找到出处了,下载看了一下
AutomationProperties.AutomationId="VerticalScrollBar"
这句去掉丝毫不见影响
msdn的介绍更像是说模拟操作,自动化测试
很可惜只找到了一段模拟鼠标点击的代码(与AutomationProperties相同的命名空间)

ButtonAutomationPeer bap = new ButtonAutomationPeer(btn);
IInvokeProvider iip = bap.GetPattern(PatternInterface.Invoke) as IInvokeProvider;
iip.Invoke();

因为设计者是为了做UI样式,所以我觉着下面这个链接还是比较靠谱的
http://social.msdn.microsoft.com/Forums/silverlight/zh-CN/cb7141c5-a045-405e-ac56-be027de72aed/automationpropertiessetname-?forum=wpfzhchs