GridPattern.GetItem(Int32, Int32) Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Belirtilen hücreyi temsil eden bir AutomationElement alır.
public:
System::Windows::Automation::AutomationElement ^ GetItem(int row, int column);
public System.Windows.Automation.AutomationElement GetItem (int row, int column);
member this.GetItem : int * int -> System.Windows.Automation.AutomationElement
Public Function GetItem (row As Integer, column As Integer) As AutomationElement
Parametreler
- row
- Int32
İlgi satırının sıra numarası.
- column
- Int32
İlgilenen sütunun sıra numarası.
Döndürülenler
AutomationElement Alınan hücreyi temsil eden bir.
Özel durumlar
İstenen satır veya sütun koordinatı sıfırdan küçük.
-veya-
İstenen satır koordinatı değerinden RowCount büyük veya sütun koordinatı değerinden ColumnCountbüyük.
Örnekler
Aşağıdaki örnekte, bir AutomationFocusChangedEvent kılavuz kapsayıcısı içindeki kılavuz öğelerinin çapraz geçişini izlemek için bir dinleyici bildirilir. Öğe özellikleri, her odak değişikliği olayında konsola yankılanır.
///--------------------------------------------------------------------
/// <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);
}
'''--------------------------------------------------------------------
''' <summary>
''' Set up grid item event listeners.
''' </summary>
''' <param name="targetControl">
''' The grid item container of interest.
''' </param>
'''--------------------------------------------------------------------
Private Sub SetGridItemEventListeners( _
ByVal targetControl As AutomationElement)
Dim gridItemFocusChangedListener As AutomationFocusChangedEventHandler = _
AddressOf OnGridItemFocusChange
Automation.AddAutomationFocusChangedEventHandler( _
gridItemFocusChangedListener)
End Sub
///--------------------------------------------------------------------
/// <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);
}
'''--------------------------------------------------------------------
''' <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 Sub OnGridItemFocusChange( _
ByVal src As Object, ByVal e As AutomationFocusChangedEventArgs)
' Make sure the element still exists. Elements such as tooltips
' can disappear before the event is processed.
Dim sourceElement As AutomationElement
Try
sourceElement = DirectCast(src, AutomationElement)
Catch exc As ElementNotAvailableException
Return
End Try
' Gets a GridItemPattern from the source of the event.
Dim gridItemPattern As GridItemPattern = _
GetGridItemPattern(sourceElement)
If gridItemPattern Is Nothing Then
Return
End If
' Gets a GridPattern from the grid container.
Dim gridPattern As GridPattern = _
GetGridPattern(gridItemPattern.Current.ContainingGrid)
If gridPattern Is Nothing Then
Return
End If
Dim gridItem As AutomationElement = Nothing
Try
gridItem = gridPattern.GetItem( _
gridItemPattern.Current.Row, gridItemPattern.Current.Column)
Catch
' 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.
End Try
' Further event processing can be done at this point.
' For the purposes of this sample we just report item properties.
Dim gridItemReport As 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())
End Sub
'''--------------------------------------------------------------------
''' <summary>
''' Handles our application shutdown.
''' </summary>
''' <param name="args">Event arguments.</param>
'''--------------------------------------------------------------------
Protected Overrides Sub OnExit(ByVal args As System.Windows.ExitEventArgs)
Automation.RemoveAllEventHandlers()
MyBase.OnExit(args)
End Sub
Açıklamalar
Kılavuz koordinatları, koordinatlara (0,0) sahip sol üst (veya yerel ayara bağlı olarak sağ üst hücre) ile sıfır tabanlıdır.
Bir hücre boşsa, o hücrenin özelliğinin ContainingGrid alınmasını desteklemek için ui otomasyonu öğesi döndürülür. Bu, kılavuzdaki alt öğelerin düzeni burada gösterildiği gibi düzensiz bir diziye benzediğinde mümkündür.
Boş Koordinatları Olan Kılavuz Denetimi Örneği