Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How to get Grid according to AutomationID

$
0
0

Hi All,

I want to get Grid by AutomationId, but failed.

Wpf Xaml: 

<Window x:Class="AutoApp.MainWindow"
        AutomationProperties.AutomationId="MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525"><Grid AutomationProperties.AutomationId="MainGrid" IsEnabled="True" Focusable="True" Visibility="Visible" > </Grid></Window>

I want to get the Grid by AutomationId, here is my code:

AutomationElement Desktop = AutomationElement.RootElement;

var window = Desktop.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.AutomationIdProperty, "MainWindow"))

var Grid = window.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.AutomationIdProperty, "MainGrid"))


I can get the window, but i can't get Grid in row 3th ?

Anyone can help me, Thank you !


Yuanzhi.Tang


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>