本文整理汇总了C#中System.Windows.Automation.GridPattern.GetItem方法的典型用法代码示例。如果您正苦于以下问题:C# GridPattern.GetItem方法的具体用法?C# GridPattern.GetItem怎么用?C# GridPattern.GetItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了GridPattern.GetItem方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetGridItemEventListeners
///--------------------------------------------------------------------
/// <summary>
/// Set up grid item event listeners.
/// </summary>
/// <param name="targetControl">
/// The grid item container of interest.
/// </param>
///--------------------------------------------------------------------
private void SetGridItemEventListeners(AutomationElement targetControl)
{
AutomationFocusChangedEventHandler gridItemFocusChangedListener =
new AutomationFocusChangedEventHandler(OnGridItemFocusChange);
Automation.AddAutomationFocusChangedEventHandler(
gridItemFocusChangedListener);
}
示例2: OnGridItemFocusChange
///--------------------------------------------------------------------
/// <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());
}
///--------------------------------------------------------------------
/// <summary>
/// Handles our application shutdown.
/// </summary>
/// <param name="args">Event arguments.</param>
///--------------------------------------------------------------------
protected override void OnExit(System.Windows.ExitEventArgs args)
{
Automation.RemoveAllEventHandlers();
base.OnExit(args);
}