![](/img/trans.png)
[英]How to refresh WPF AutomationElement with DataTemplate - Windows UI Automation
[英]UI Automation: How to change value of a horizontal scrollbar AutomationElement
我试图将水平滚动条的值从-1更改为-2。 我可以访问它。.但是接下来我必须更改它的值..
AutomationElement _sideBar = _ClickButtonElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, "WindowsForms10.SCROLLBAR.app.0.378734a"));
_clickButtonElement是滚动条的父窗口的AutomationElement。
滚动条通常支持RangeValuePattern 。 使用类似:
RangeValuePattern range = scrollbar.GetCurrentPattern(RangeValuePattern.Pattern) as RangeValuePattern;
range.SetValue(50); // Set to half way point
请注意,通常将滚动条归一化为0..100,而不考虑内部值。 因此,如果滚动条内部使用值-5至5,则滚动条的中点0实际上将通过RangeValuePattern公开为50。
您可能要使用“ 检查”工具来确保获得正确的元素,并且它也支持此模式。 在编写任何代码之前,还可以使用Inspect通过其UI调用RangeValue.SetValue()。
AutomationElement aeForm = AutomationElement.FromHandle(windowPtr);
AutomationElementCollection buttonCollection = aeForm.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ScrollBar));
AutomationElement aeButton = buttonCollection[1];
RangeValuePattern rcpattern = (RangeValuePattern)aeButton.GetCurrentPattern(RangeValuePattern.Pattern);
rcpattern.SetValue(50.00);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.