// </Snippet103> // <Snippet104> ///-------------------------------------------------------------------- /// <summary> /// Gets the current property values from target. /// </summary> /// <param name="gridItemPattern"> /// A GridItemPattern control pattern obtained from /// an automation element representing a target control. /// </param> /// <param name="automationProperty"> /// The automation property of interest. /// </param> /// <returns> /// An integer object representing the requested property value. /// </returns> ///-------------------------------------------------------------------- private object GetGridItemProperties( GridItemPattern gridItemPattern, AutomationProperty automationProperty) { if (automationProperty.Id == GridItemPattern.ColumnProperty.Id) { return(gridItemPattern.Current.Column); } if (automationProperty.Id == GridItemPattern.RowProperty.Id) { return(gridItemPattern.Current.Row); } if (automationProperty.Id == GridItemPattern.ColumnSpanProperty.Id) { return(gridItemPattern.Current.ColumnSpan); } if (automationProperty.Id == GridItemPattern.RowSpanProperty.Id) { return(gridItemPattern.Current.RowSpan); } return(null); }
public void GridPatternCachedTest() { CacheRequest req = new CacheRequest(); req.Add(GridItemPattern.Pattern); req.Add(GridPattern.Pattern); req.Add(GridPattern.RowCountProperty); req.Add(GridPattern.ColumnCountProperty); req.Add(GridItemPattern.RowProperty); req.Add(GridItemPattern.ColumnProperty); req.Add(GridItemPattern.ContainingGridProperty); using (req.Activate()) { AutomationElement itemsView = ExplorerTargetTests.explorerHost.Element.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.ClassNameProperty, "UIItemsView")); Assert.IsNotNull(itemsView); // Try out the Grid Pattern GridPattern grid = (GridPattern)itemsView.GetCachedPattern(GridPattern.Pattern); Assert.IsTrue(grid.Cached.ColumnCount > 0); Assert.IsTrue(grid.Cached.RowCount > 0); // GridItem AutomationElement gridItemElement = grid.GetItem(0, 0); Assert.IsNotNull(gridItemElement); GridItemPattern gridItem = (GridItemPattern)gridItemElement.GetCachedPattern(GridItemPattern.Pattern); Assert.AreEqual(gridItem.Cached.Row, 0); Assert.AreEqual(gridItem.Cached.Column, 0); Assert.AreEqual(gridItem.Cached.ContainingGrid, itemsView); } }
/// ------------------------------------------------------------------- /// <summary></summary> /// ------------------------------------------------------------------- public GridItemTests(AutomationElement element, TestPriorities priority, string dirResults, bool testEvents, TypeOfControl typeOfControl, IApplicationCommands commands) : base(element, TestSuite, priority, typeOfControl, TypeOfPattern.GridItem, dirResults, testEvents, commands) { _pattern = (GridItemPattern)element.GetCurrentPattern(GridItemPattern.Pattern); if (_pattern == null) { throw new Exception(Helpers.PatternNotSupported); } }
public static bool TryGetGridItemPattern(this AutomationElement element, out GridItemPattern result) { if (element.TryGetCurrentPattern(System.Windows.Automation.GridItemPattern.Pattern, out var pattern)) { result = (GridItemPattern)pattern; return(true); } result = null; return(false); }
// </Snippet100> // <Snippet101> ///-------------------------------------------------------------------- /// <summary> /// Obtains a GridItemPattern control pattern from an /// automation element. /// </summary> /// <param name="targetControl"> /// The automation element of interest. /// </param> /// <returns> /// A GridItemPattern object. /// </returns> ///-------------------------------------------------------------------- private GridItemPattern GetGridItemPattern( AutomationElement targetControl) { GridItemPattern gridItemPattern = null; try { gridItemPattern = targetControl.GetCurrentPattern( GridItemPattern.Pattern) as GridItemPattern; } // Object doesn't support the // GridPattern control pattern catch (InvalidOperationException) { return(null); } return(gridItemPattern); }
public void GridPatternTest() { AutomationElement itemsView = ExplorerTargetTests.explorerHost.Element.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.ClassNameProperty, "UIItemsView")); Assert.IsNotNull(itemsView); // Try out the Grid Pattern GridPattern grid = (GridPattern)itemsView.GetCurrentPattern(GridPattern.Pattern); Assert.IsTrue(grid.Current.ColumnCount > 0); Assert.IsTrue(grid.Current.RowCount > 0); // GridItem AutomationElement gridItemElement = grid.GetItem(0, 0); Assert.IsNotNull(gridItemElement); GridItemPattern gridItem = (GridItemPattern)gridItemElement.GetCurrentPattern(GridItemPattern.Pattern); Assert.AreEqual(gridItem.Current.Row, 0); Assert.AreEqual(gridItem.Current.Column, 0); Assert.AreEqual(gridItem.Current.ContainingGrid, itemsView); }
// </Snippet102> // <Snippet103> ///-------------------------------------------------------------------- /// <summary> /// Event handler for grid item focus change. /// Can be used to track traversal of individual grid items /// within a grid. /// </summary> /// <param name="src">Object that raised the event.</param> /// <param name="e">Event arguments.</param> ///-------------------------------------------------------------------- private void OnGridItemFocusChange( object src, AutomationFocusChangedEventArgs e) { // Make sure the element still exists. Elements such as tooltips // can disappear before the event is processed. AutomationElement sourceElement; try { sourceElement = src as AutomationElement; } catch (ElementNotAvailableException) { return; } // Gets a GridItemPattern from the source of the event. GridItemPattern gridItemPattern = GetGridItemPattern(sourceElement); if (gridItemPattern == null) { return; } // Gets a GridPattern from the grid container. GridPattern gridPattern = GetGridPattern(gridItemPattern.Current.ContainingGrid); if (gridPattern == null) { return; } AutomationElement gridItem = null; try { gridItem = gridPattern.GetItem( gridItemPattern.Current.Row, gridItemPattern.Current.Column); } catch (ArgumentOutOfRangeException) { // If the requested row coordinate is larger than the RowCount // or the column coordinate is larger than the ColumnCount. // -- OR -- // If either of the requested row or column coordinates // are less than zero. // TO DO: error handling. } // Further event processing can be done at this point. // For the purposes of this sample we just report item properties. StringBuilder gridItemReport = new StringBuilder(); gridItemReport.AppendLine( gridItemPattern.Current.Row.ToString()).AppendLine( gridItemPattern.Current.Column.ToString()).AppendLine( gridItemPattern.Current.RowSpan.ToString()).AppendLine( gridItemPattern.Current.ColumnSpan.ToString()).AppendLine( gridItem.Current.AutomationId.ToString()); Console.WriteLine(gridItemReport.ToString()); }
public TableItemWrapper(AutomationWrapper automationWrapper, GridItemPattern pattern) : base(automationWrapper, pattern) { }
/// <summary> /// Gets the number of rows spanned by a cell or item. /// </summary> /// <param name="control">The UI Automation element</param> /// <returns> /// The number of rows spanned by a cell or item /// </returns> internal static int GetRowSpan(AutomationElement control) { GridItemPattern pat = (GridItemPattern)CommonUIAPatternHelpers.CheckPatternSupport(GridItemPattern.Pattern, control); return(pat.Current.RowSpan); }
/// <summary> /// Gets a UI Automation provider that implements IGridProvider and represents the container of the cell or item /// </summary> /// <param name="control">The UI Automation element</param> /// <returns> /// returns an object, stored as an internal variable that represents the grid container /// </returns> internal static AutomationElement GetContainingGrid(AutomationElement control) { GridItemPattern pat = (GridItemPattern)CommonUIAPatternHelpers.CheckPatternSupport(GridItemPattern.Pattern, control); return(pat.Current.ContainingGrid); }
public void setGridPattern(AutomationElement AE) { patt_GridItemPattern = Retry.For(() => ((GridItemPattern)AE.GetCurrentPattern(GridItemPattern.Pattern)), TimeSpan.FromSeconds(10)); }