public ScrollAxis GetScrollAxis(OrientationType orientation) { return (ScrollAxis)STAHelper.Invoke( delegate() { if(!scrollAxes.ContainsKey(orientation)) { object pattern; if(AutomationElement.TryGetCurrentPattern(ScrollPattern.Pattern, out pattern)) { scrollAxes[orientation] = new ScrollPatternAxis((ScrollPattern)pattern, orientation); } else if(ControlType == ControlType.ScrollBar) { if(orientation == (OrientationType)this[AutomationElement.OrientationProperty]) scrollAxes[orientation] = new ScrollBarAxis(AutomationElement); else throw new ArgumentException("Cannot get "+orientation+" scroll-axis for a scrollbar that is not "+orientation); } else if (ControlType == ControlType.Pane && Class == "ScrollBar") { scrollAxes[orientation] = new PaneScrollAxis(AutomationElement); } else { Condition scrollBarCondition = new AndCondition( new PropertyCondition2(AutomationElement.OrientationProperty, orientation), new PropertyCondition2(AutomationElement.ControlTypeProperty, ControlType.ScrollBar) ); Condition scrollPaneCondition = new AndCondition( new PropertyCondition2(AutomationElement.ControlTypeProperty, ControlType.Pane), new PropertyCondition2(AutomationElement.ClassNameProperty, "ScrollBar") ); Condition scrollPatternCondition = new PropertyCondition2(AutomationElement.IsScrollPatternAvailableProperty, true); Condition condition = new OrCondition(scrollBarCondition, scrollPaneCondition, scrollPatternCondition); List<AutomationElement> matches = Twin.View.Search.FindAll(AutomationElement, TreeScope.Descendants, 1 ,condition, (int)AutomationElement.GetCurrentPropertyValue(AutomationElement.ProcessIdProperty)); for(int i=0; i<matches.Count; i++) { if(matches[i].GetCurrentPropertyValue(AutomationElement.ControlTypeProperty) != ControlType.Pane) continue; if((bool)matches[i].GetCurrentPropertyValue(AutomationElement.IsScrollPatternAvailableProperty)) continue; Rect bounds = (Rect)matches[i].GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty); if(orientation == OrientationType.Horizontal && bounds.Height > bounds.Width) matches.RemoveAt(i--); if(orientation == OrientationType.Vertical && bounds.Width > bounds.Height) matches.RemoveAt(i--); } if (matches.Count == 0) return null; if (matches.Count > 1) throw new ArgumentException("Scrollable Axis for element ambiguous"); return Element.Create(matches[0], processId).GetScrollAxis(orientation); } } return scrollAxes[orientation]; } ); }
public ScrollAxis GetScrollAxis(OrientationType orientation) { return((ScrollAxis)STAHelper.Invoke( delegate() { if (!scrollAxes.ContainsKey(orientation)) { object pattern; if (AutomationElement.TryGetCurrentPattern(ScrollPattern.Pattern, out pattern)) { scrollAxes[orientation] = new ScrollPatternAxis((ScrollPattern)pattern, orientation); } else if (ControlType == ControlType.ScrollBar) { if (orientation == (OrientationType)this[AutomationElement.OrientationProperty]) { scrollAxes[orientation] = new ScrollBarAxis(AutomationElement); } else { throw new ArgumentException("Cannot get " + orientation + " scroll-axis for a scrollbar that is not " + orientation); } } else if (ControlType == ControlType.Pane && Class == "ScrollBar") { scrollAxes[orientation] = new PaneScrollAxis(AutomationElement); } else { Condition scrollBarCondition = new AndCondition( new PropertyCondition2(AutomationElement.OrientationProperty, orientation), new PropertyCondition2(AutomationElement.ControlTypeProperty, ControlType.ScrollBar) ); Condition scrollPaneCondition = new AndCondition( new PropertyCondition2(AutomationElement.ControlTypeProperty, ControlType.Pane), new PropertyCondition2(AutomationElement.ClassNameProperty, "ScrollBar") ); Condition scrollPatternCondition = new PropertyCondition2(AutomationElement.IsScrollPatternAvailableProperty, true); Condition condition = new OrCondition(scrollBarCondition, scrollPaneCondition, scrollPatternCondition); List <AutomationElement> matches = Twin.View.Search.FindAll(AutomationElement, TreeScope.Descendants, 1, condition, (int)AutomationElement.GetCurrentPropertyValue(AutomationElement.ProcessIdProperty)); for (int i = 0; i < matches.Count; i++) { if (matches[i].GetCurrentPropertyValue(AutomationElement.ControlTypeProperty) != ControlType.Pane) { continue; } if ((bool)matches[i].GetCurrentPropertyValue(AutomationElement.IsScrollPatternAvailableProperty)) { continue; } Rect bounds = (Rect)matches[i].GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty); if (orientation == OrientationType.Horizontal && bounds.Height > bounds.Width) { matches.RemoveAt(i--); } if (orientation == OrientationType.Vertical && bounds.Width > bounds.Height) { matches.RemoveAt(i--); } } if (matches.Count == 0) { return null; } if (matches.Count > 1) { throw new ArgumentException("Scrollable Axis for element ambiguous"); } return Element.Create(matches[0], processId).GetScrollAxis(orientation); } } return scrollAxes[orientation]; } )); }