GridAutomationHelper.AddAutomationRequestedHandler(DependencyObject, RoutedEventHandler) Method
Adds an event handler to the AutomationRequested attached event.
Namespace: DevExpress.Xpf.Grid.Automation
Assembly: DevExpress.Xpf.Grid.v25.2.dll
Declaration
public static void AddAutomationRequestedHandler(
DependencyObject dependencyObject,
RoutedEventHandler handler
)
Parameters
| Name | Type | Description |
|---|---|---|
| dependencyObject | DependencyObject | An object that receives the event handler. |
| handler | RoutedEventHandler | An event handler. |
Remarks
Use the AddAutomationRequestedHandler method to subscribe to the AutomationRequested event. In the handler, cast an event data object to the AutomationEventArgs class and specify a custom value.
Example
The following code example subscribes to the AutomationRequested event and changes values announced by a screen reader app when the target row or cell is focused:
// Subscribe
GridAutomationHelper.AddAutomationRequestedHandler(tableView, OnAutomationRequested);
// Unsubscribe (when no longer needed)
// GridAutomationHelper.RemoveAutomationRequestedHandler(tableView, OnAutomationRequested);
void OnAutomationRequested(object sender, RoutedEventArgs e) {
var args = (AutomationEventArgs)e;
if (args.AutomationProperty != AutomationProperty.Name)
return;
switch (args) {
case CellAutomationEventArgs cell:
var header = cell.Column.HeaderCaption ?? cell.Column.FieldName;
var value = cell.Cell.Value?.ToString() ?? string.Empty;
args.AutomationValue = $"{header} {value}";
break;
case RowAutomationEventArgs row:
var grid = row.DataControl as GridControl;
var view = grid?.View as TableView;
if (view == null) return;
var parts = view.VisibleColumns
.Select(c => $"{c.HeaderCaption ?? c.FieldName} {view.GetCellValue(row.RowHandle, c)}");
args.AutomationValue = string.Join(", ", parts);
break;
}
}
See Also