public override object GetPropertyValue(string name) { var pattern = automationElement.Patterns.LegacyIAccessible.Pattern; switch (name.ToLower()) { case Indexes.Value: return(pattern.Value.ValueOrDefault); case Indexes.DefaultAction: return(pattern.DefaultAction.ValueOrDefault); case Indexes.Description: return(pattern.Description.ValueOrDefault); case Indexes.Help: return(pattern.Help.ValueOrDefault); case Indexes.Name: return(pattern.Name.ValueOrDefault); case Indexes.State: return(AccessibilityTextResolver.GetStateText(pattern.State.ValueOrDefault)); case Indexes.Role: return(AccessibilityTextResolver.GetRoleText(pattern.Role.ValueOrDefault)); case Indexes.KeyboardShortcut: return(pattern.KeyboardShortcut.ValueOrDefault); } throw new ArgumentException($"Unknown index '{name}'"); }
private List <DetailGroupViewModel> LoadDetails() { var detailGroups = new List <DetailGroupViewModel>(); // Element identification var identification = new List <DetailViewModel> { new DetailViewModel("AutomationId", AutomationElement.Current.AutomationId), new DetailViewModel("Name", AutomationElement.Current.Name), new DetailViewModel("ClassName", AutomationElement.Current.ClassName), new DetailViewModel("ControlType", AutomationElement.Current.ControlType), new DetailViewModel("LocalizedControlType", AutomationElement.Current.LocalizedControlType), new DetailViewModel("FrameworkType", AutomationElement.FrameworkType), new DetailViewModel("FrameworkId", AutomationElement.Current.FrameworkId), new DetailViewModel("ProcessId", AutomationElement.Current.ProcessId), }; detailGroups.Add(new DetailGroupViewModel("Identification", identification)); // Element details var details = new List <DetailViewModel> { new DetailViewModel("IsEnabled", AutomationElement.Current.IsEnabled), new DetailViewModel("IsOffscreen", AutomationElement.Current.IsOffscreen), new DetailViewModel("BoundingRectangle", AutomationElement.Current.BoundingRectangle), new DetailViewModel("HelpText", AutomationElement.Current.HelpText), new DetailViewModel("IsPassword", AutomationElement.Current.IsPassword), new DetailViewModel("NativeWindowHandle", String.Format("{0} ({0:X8})", AutomationElement.Current.NativeWindowHandle.ToInt32())) }; detailGroups.Add(new DetailGroupViewModel("Details", details)); // Pattern details var allSupportedPatterns = AutomationElement.BasicAutomationElement.GetSupportedPatterns(); var allPatterns = AutomationElement.Automation.PatternLibrary.AllSupportedPatterns; var patterns = new List <DetailViewModel>(); foreach (var pattern in allPatterns) { var hasPattern = allSupportedPatterns.Contains(pattern); patterns.Add(new DetailViewModel(pattern.Name + "Pattern", hasPattern ? "Yes" : "No") { Important = hasPattern }); } detailGroups.Add(new DetailGroupViewModel("Pattern Support", patterns)); // TODO: Add all missing pattern properties // GridItemPattern if (allSupportedPatterns.Contains(AutomationElement.Automation.PatternLibrary.GridItemPattern)) { var pattern = AutomationElement.PatternFactory.GetGridItemPattern(); var patternDetails = new List <DetailViewModel> { new DetailViewModel("Column", pattern.Current.Column), new DetailViewModel("ColumnSpan", pattern.Current.ColumnSpan), new DetailViewModel("Row", pattern.Current.Row), new DetailViewModel("RowSpan", pattern.Current.RowSpan), new DetailViewModel("ContainingGrid", pattern.Current.ContainingGrid) }; detailGroups.Add(new DetailGroupViewModel("GridItem Pattern", patternDetails)); } // GridPattern if (allSupportedPatterns.Contains(AutomationElement.Automation.PatternLibrary.GridPattern)) { var pattern = AutomationElement.PatternFactory.GetGridPattern(); var patternDetails = new List <DetailViewModel> { new DetailViewModel("ColumnCount", pattern.Current.ColumnCount), new DetailViewModel("RowCount", pattern.Current.RowCount) }; detailGroups.Add(new DetailGroupViewModel("Grid Pattern", patternDetails)); } // LegacyIAccessiblePattern if (allSupportedPatterns.Contains(AutomationElement.Automation.PatternLibrary.LegacyIAccessiblePattern)) { var pattern = AutomationElement.PatternFactory.GetLegacyIAccessiblePattern(); var patternDetails = new List <DetailViewModel> { new DetailViewModel("Name", pattern.Current.Name), new DetailViewModel("State", AccessibilityTextResolver.GetStateText(pattern.Current.State)), new DetailViewModel("Role", AccessibilityTextResolver.GetRoleText(pattern.Current.Role)), new DetailViewModel("Value", pattern.Current.Value), new DetailViewModel("ChildId", pattern.Current.ChildId), new DetailViewModel("DefaultAction", pattern.Current.DefaultAction), new DetailViewModel("Description", pattern.Current.Description), new DetailViewModel("Help", pattern.Current.Help), new DetailViewModel("KeyboardShortcut", pattern.Current.KeyboardShortcut), new DetailViewModel("Selection", pattern.Current.Selection) }; detailGroups.Add(new DetailGroupViewModel("LegacyIAccessible Pattern", patternDetails)); } // RangeValuePattern if (allSupportedPatterns.Contains(AutomationElement.Automation.PatternLibrary.RangeValuePattern)) { var pattern = AutomationElement.PatternFactory.GetRangeValuePattern(); var patternDetails = new List <DetailViewModel> { new DetailViewModel("IsReadOnly", pattern.Current.IsReadOnly), new DetailViewModel("SmallChange", pattern.Current.SmallChange), new DetailViewModel("LargeChange", pattern.Current.LargeChange), new DetailViewModel("Minimum", pattern.Current.Minimum), new DetailViewModel("Maximum", pattern.Current.Maximum), new DetailViewModel("Value", pattern.Current.Value) }; detailGroups.Add(new DetailGroupViewModel("RangeValue Pattern", patternDetails)); } // ScrollPattern if (allSupportedPatterns.Contains(AutomationElement.Automation.PatternLibrary.ScrollPattern)) { var pattern = AutomationElement.PatternFactory.GetScrollPattern(); var patternDetails = new List <DetailViewModel> { new DetailViewModel("HorizontalScrollPercent", pattern.Current.HorizontalScrollPercent), new DetailViewModel("HorizontalViewSize", pattern.Current.HorizontalViewSize), new DetailViewModel("HorizontallyScrollable", pattern.Current.HorizontallyScrollable), new DetailViewModel("VerticalScrollPercent", pattern.Current.VerticalScrollPercent), new DetailViewModel("VerticalViewSize", pattern.Current.VerticalViewSize), new DetailViewModel("VerticallyScrollable", pattern.Current.VerticallyScrollable) }; detailGroups.Add(new DetailGroupViewModel("Scroll Pattern", patternDetails)); } // SelectionItemPattern if (allSupportedPatterns.Contains(AutomationElement.Automation.PatternLibrary.SelectionItemPattern)) { var pattern = AutomationElement.PatternFactory.GetSelectionItemPattern(); var patternDetails = new List <DetailViewModel> { new DetailViewModel("IsSelected", pattern.Current.IsSelected), new DetailViewModel("SelectionContainer", pattern.Current.SelectionContainer) }; detailGroups.Add(new DetailGroupViewModel("SelectionItem Pattern", patternDetails)); } // SelectionPattern if (allSupportedPatterns.Contains(AutomationElement.Automation.PatternLibrary.SelectionPattern)) { var pattern = AutomationElement.PatternFactory.GetSelectionPattern(); var patternDetails = new List <DetailViewModel> { new DetailViewModel("Selection", pattern.Current.Selection), new DetailViewModel("CanSelectMultiple", pattern.Current.CanSelectMultiple), new DetailViewModel("IsSelectionRequired", pattern.Current.IsSelectionRequired) }; detailGroups.Add(new DetailGroupViewModel("Selection Pattern", patternDetails)); } // TableItemPattern if (allSupportedPatterns.Contains(AutomationElement.Automation.PatternLibrary.TableItemPattern)) { var pattern = AutomationElement.PatternFactory.GetTableItemPattern(); var patternDetails = new List <DetailViewModel> { new DetailViewModel("ColumnHeaderItems", pattern.Current.ColumnHeaderItems), new DetailViewModel("RowHeaderItems", pattern.Current.RowHeaderItems) }; detailGroups.Add(new DetailGroupViewModel("TableItem Pattern", patternDetails)); } // TablePattern if (allSupportedPatterns.Contains(AutomationElement.Automation.PatternLibrary.TablePattern)) { var pattern = AutomationElement.PatternFactory.GetTablePattern(); var patternDetails = new List <DetailViewModel> { new DetailViewModel("ColumnHeaderItems", pattern.Current.ColumnHeaders), new DetailViewModel("RowHeaderItems", pattern.Current.RowHeaders), new DetailViewModel("RowOrColumnMajor", pattern.Current.RowOrColumnMajor) }; detailGroups.Add(new DetailGroupViewModel("Table Pattern", patternDetails)); } // TogglePattern if (allSupportedPatterns.Contains(AutomationElement.Automation.PatternLibrary.TogglePattern)) { var pattern = AutomationElement.PatternFactory.GetTogglePattern(); var patternDetails = new List <DetailViewModel> { new DetailViewModel("ToggleState", pattern.Current.ToggleState) }; detailGroups.Add(new DetailGroupViewModel("Toggle Pattern", patternDetails)); } // ValuePattern if (allSupportedPatterns.Contains(AutomationElement.Automation.PatternLibrary.ValuePattern)) { var pattern = AutomationElement.PatternFactory.GetValuePattern(); var patternDetails = new List <DetailViewModel> { new DetailViewModel("IsReadOnly", pattern.Current.IsReadOnly), new DetailViewModel("Value", pattern.Current.Value) }; detailGroups.Add(new DetailGroupViewModel("Value Pattern", patternDetails)); } // WindowPattern if (allSupportedPatterns.Contains(AutomationElement.Automation.PatternLibrary.WindowPattern)) { var pattern = AutomationElement.PatternFactory.GetWindowPattern(); var patternDetails = new List <DetailViewModel> { new DetailViewModel("IsModal", pattern.Current.IsModal), new DetailViewModel("IsTopmost", pattern.Current.IsTopmost), new DetailViewModel("CanMinimize", pattern.Current.CanMinimize), new DetailViewModel("CanMaximize", pattern.Current.CanMaximize), new DetailViewModel("WindowVisualState", pattern.Current.WindowVisualState), new DetailViewModel("WindowInteractionState", pattern.Current.WindowInteractionState) }; detailGroups.Add(new DetailGroupViewModel("Window Pattern", patternDetails)); } return(detailGroups); }
private List <DetailGroupViewModel> LoadDetails() { var detailGroups = new List <DetailGroupViewModel>(); var cacheRequest = new CacheRequest(); cacheRequest.TreeScope = TreeScope.Element; cacheRequest.Add(AutomationElement.Automation.PropertyLibrary.Element.AutomationId); cacheRequest.Add(AutomationElement.Automation.PropertyLibrary.Element.Name); cacheRequest.Add(AutomationElement.Automation.PropertyLibrary.Element.ClassName); cacheRequest.Add(AutomationElement.Automation.PropertyLibrary.Element.ControlType); cacheRequest.Add(AutomationElement.Automation.PropertyLibrary.Element.LocalizedControlType); cacheRequest.Add(AutomationElement.Automation.PropertyLibrary.Element.FrameworkId); cacheRequest.Add(AutomationElement.Automation.PropertyLibrary.Element.ProcessId); cacheRequest.Add(AutomationElement.Automation.PropertyLibrary.Element.IsEnabled); cacheRequest.Add(AutomationElement.Automation.PropertyLibrary.Element.IsOffscreen); cacheRequest.Add(AutomationElement.Automation.PropertyLibrary.Element.BoundingRectangle); cacheRequest.Add(AutomationElement.Automation.PropertyLibrary.Element.HelpText); cacheRequest.Add(AutomationElement.Automation.PropertyLibrary.Element.IsPassword); cacheRequest.Add(AutomationElement.Automation.PropertyLibrary.Element.NativeWindowHandle); using (cacheRequest.Activate()) { var elementCached = AutomationElement.FindFirst(TreeScope.Element, new TrueCondition()); // Element identification var identification = new List <IDetailViewModel> { DetailViewModel.FromAutomationProperty("AutomationId", elementCached.Properties.AutomationId), DetailViewModel.FromAutomationProperty("Name", elementCached.Properties.Name), DetailViewModel.FromAutomationProperty("ClassName", elementCached.Properties.ClassName), DetailViewModel.FromAutomationProperty("ControlType", elementCached.Properties.ControlType), DetailViewModel.FromAutomationProperty("LocalizedControlType", elementCached.Properties.LocalizedControlType), new DetailViewModel("FrameworkType", elementCached.FrameworkType.ToString()), DetailViewModel.FromAutomationProperty("FrameworkId", elementCached.Properties.FrameworkId), DetailViewModel.FromAutomationProperty("ProcessId", elementCached.Properties.ProcessId), }; detailGroups.Add(new DetailGroupViewModel("Identification", identification)); // Element details var details = new List <DetailViewModel> { DetailViewModel.FromAutomationProperty("IsEnabled", elementCached.Properties.IsEnabled), DetailViewModel.FromAutomationProperty("IsOffscreen", elementCached.Properties.IsOffscreen), DetailViewModel.FromAutomationProperty("BoundingRectangle", elementCached.Properties.BoundingRectangle), DetailViewModel.FromAutomationProperty("HelpText", elementCached.Properties.HelpText), DetailViewModel.FromAutomationProperty("IsPassword", elementCached.Properties.IsPassword) }; // Special handling for NativeWindowHandle var nativeWindowHandle = elementCached.Properties.NativeWindowHandle.ValueOrDefault; var nativeWindowHandleString = "Not Supported"; if (nativeWindowHandle != default(IntPtr)) { nativeWindowHandleString = String.Format("{0} ({0:X8})", nativeWindowHandle.ToInt32()); } details.Add(new DetailViewModel("NativeWindowHandle", nativeWindowHandleString)); detailGroups.Add(new DetailGroupViewModel("Details", details)); } // Pattern details var allSupportedPatterns = AutomationElement.BasicAutomationElement.GetSupportedPatterns(); var allPatterns = AutomationElement.Automation.PatternLibrary.AllForCurrentFramework; var patterns = new List <DetailViewModel>(); foreach (var pattern in allPatterns) { var hasPattern = allSupportedPatterns.Contains(pattern); patterns.Add(new DetailViewModel(pattern.Name + "Pattern", hasPattern ? "Yes" : "No") { Important = hasPattern }); } detailGroups.Add(new DetailGroupViewModel("Pattern Support", patterns)); // GridItemPattern if (allSupportedPatterns.Contains(AutomationElement.Automation.PatternLibrary.GridItemPattern)) { var pattern = AutomationElement.Patterns.GridItem.Pattern; var patternDetails = new List <DetailViewModel> { DetailViewModel.FromAutomationProperty("Column", pattern.Column), DetailViewModel.FromAutomationProperty("ColumnSpan", pattern.ColumnSpan), DetailViewModel.FromAutomationProperty("Row", pattern.Row), DetailViewModel.FromAutomationProperty("RowSpan", pattern.RowSpan), DetailViewModel.FromAutomationProperty("ContainingGrid", pattern.ContainingGrid) }; detailGroups.Add(new DetailGroupViewModel("GridItem Pattern", patternDetails)); } // GridPattern if (allSupportedPatterns.Contains(AutomationElement.Automation.PatternLibrary.GridPattern)) { var pattern = AutomationElement.Patterns.Grid.Pattern; var patternDetails = new List <DetailViewModel> { DetailViewModel.FromAutomationProperty("ColumnCount", pattern.ColumnCount), DetailViewModel.FromAutomationProperty("RowCount", pattern.RowCount) }; detailGroups.Add(new DetailGroupViewModel("Grid Pattern", patternDetails)); } // LegacyIAccessiblePattern if (allSupportedPatterns.Contains(AutomationElement.Automation.PatternLibrary.LegacyIAccessiblePattern)) { var pattern = AutomationElement.Patterns.LegacyIAccessible.Pattern; var patternDetails = new List <DetailViewModel> { DetailViewModel.FromAutomationProperty("Name", pattern.Name), new DetailViewModel("State", AccessibilityTextResolver.GetStateText(pattern.State.ValueOrDefault)), new DetailViewModel("Role", AccessibilityTextResolver.GetRoleText(pattern.Role.ValueOrDefault)), DetailViewModel.FromAutomationProperty("Value", pattern.Value), DetailViewModel.FromAutomationProperty("ChildId", pattern.ChildId), DetailViewModel.FromAutomationProperty("DefaultAction", pattern.DefaultAction), DetailViewModel.FromAutomationProperty("Description", pattern.Description), DetailViewModel.FromAutomationProperty("Help", pattern.Help), DetailViewModel.FromAutomationProperty("KeyboardShortcut", pattern.KeyboardShortcut), DetailViewModel.FromAutomationProperty("Selection", pattern.Selection) }; detailGroups.Add(new DetailGroupViewModel("LegacyIAccessible Pattern", patternDetails)); } // RangeValuePattern if (allSupportedPatterns.Contains(AutomationElement.Automation.PatternLibrary.RangeValuePattern)) { var pattern = AutomationElement.Patterns.RangeValue.Pattern; var patternDetails = new List <DetailViewModel> { DetailViewModel.FromAutomationProperty("IsReadOnly", pattern.IsReadOnly), DetailViewModel.FromAutomationProperty("SmallChange", pattern.SmallChange), DetailViewModel.FromAutomationProperty("LargeChange", pattern.LargeChange), DetailViewModel.FromAutomationProperty("Minimum", pattern.Minimum), DetailViewModel.FromAutomationProperty("Maximum", pattern.Maximum), DetailViewModel.FromAutomationProperty("Value", pattern.Value) }; detailGroups.Add(new DetailGroupViewModel("RangeValue Pattern", patternDetails)); } // ScrollPattern if (allSupportedPatterns.Contains(AutomationElement.Automation.PatternLibrary.ScrollPattern)) { var pattern = AutomationElement.Patterns.Scroll.Pattern; var patternDetails = new List <DetailViewModel> { DetailViewModel.FromAutomationProperty("HorizontalScrollPercent", pattern.HorizontalScrollPercent), DetailViewModel.FromAutomationProperty("HorizontalViewSize", pattern.HorizontalViewSize), DetailViewModel.FromAutomationProperty("HorizontallyScrollable", pattern.HorizontallyScrollable), DetailViewModel.FromAutomationProperty("VerticalScrollPercent", pattern.VerticalScrollPercent), DetailViewModel.FromAutomationProperty("VerticalViewSize", pattern.VerticalViewSize), DetailViewModel.FromAutomationProperty("VerticallyScrollable", pattern.VerticallyScrollable) }; detailGroups.Add(new DetailGroupViewModel("Scroll Pattern", patternDetails)); } // SelectionItemPattern if (allSupportedPatterns.Contains(AutomationElement.Automation.PatternLibrary.SelectionItemPattern)) { var pattern = AutomationElement.Patterns.SelectionItem.Pattern; var patternDetails = new List <DetailViewModel> { DetailViewModel.FromAutomationProperty("IsSelected", pattern.IsSelected), DetailViewModel.FromAutomationProperty("SelectionContainer", pattern.SelectionContainer) }; detailGroups.Add(new DetailGroupViewModel("SelectionItem Pattern", patternDetails)); } // SelectionPattern if (allSupportedPatterns.Contains(AutomationElement.Automation.PatternLibrary.SelectionPattern)) { var pattern = AutomationElement.Patterns.Selection.Pattern; var patternDetails = new List <DetailViewModel> { DetailViewModel.FromAutomationProperty("Selection", pattern.Selection), DetailViewModel.FromAutomationProperty("CanSelectMultiple", pattern.CanSelectMultiple), DetailViewModel.FromAutomationProperty("IsSelectionRequired", pattern.IsSelectionRequired) }; detailGroups.Add(new DetailGroupViewModel("Selection Pattern", patternDetails)); } // TableItemPattern if (allSupportedPatterns.Contains(AutomationElement.Automation.PatternLibrary.TableItemPattern)) { var pattern = AutomationElement.Patterns.TableItem.Pattern; var patternDetails = new List <DetailViewModel> { DetailViewModel.FromAutomationProperty("ColumnHeaderItems", pattern.ColumnHeaderItems), DetailViewModel.FromAutomationProperty("RowHeaderItems", pattern.RowHeaderItems) }; detailGroups.Add(new DetailGroupViewModel("TableItem Pattern", patternDetails)); } // TablePattern if (allSupportedPatterns.Contains(AutomationElement.Automation.PatternLibrary.TablePattern)) { var pattern = AutomationElement.Patterns.Table.Pattern; var patternDetails = new List <DetailViewModel> { DetailViewModel.FromAutomationProperty("ColumnHeaderItems", pattern.ColumnHeaders), DetailViewModel.FromAutomationProperty("RowHeaderItems", pattern.RowHeaders), DetailViewModel.FromAutomationProperty("RowOrColumnMajor", pattern.RowOrColumnMajor) }; detailGroups.Add(new DetailGroupViewModel("Table Pattern", patternDetails)); } // TogglePattern if (allSupportedPatterns.Contains(AutomationElement.Automation.PatternLibrary.TogglePattern)) { var pattern = AutomationElement.Patterns.Toggle.Pattern; var patternDetails = new List <DetailViewModel> { DetailViewModel.FromAutomationProperty("ToggleState", pattern.ToggleState) }; detailGroups.Add(new DetailGroupViewModel("Toggle Pattern", patternDetails)); } // ValuePattern if (allSupportedPatterns.Contains(AutomationElement.Automation.PatternLibrary.ValuePattern)) { var pattern = AutomationElement.Patterns.Value.Pattern; var patternDetails = new List <DetailViewModel> { DetailViewModel.FromAutomationProperty("IsReadOnly", pattern.IsReadOnly), DetailViewModel.FromAutomationProperty("Value", pattern.Value) }; detailGroups.Add(new DetailGroupViewModel("Value Pattern", patternDetails)); } // WindowPattern if (allSupportedPatterns.Contains(AutomationElement.Automation.PatternLibrary.WindowPattern)) { var pattern = AutomationElement.Patterns.Window.Pattern; var patternDetails = new List <DetailViewModel> { DetailViewModel.FromAutomationProperty("IsModal", pattern.IsModal), DetailViewModel.FromAutomationProperty("IsTopmost", pattern.IsTopmost), DetailViewModel.FromAutomationProperty("CanMinimize", pattern.CanMinimize), DetailViewModel.FromAutomationProperty("CanMaximize", pattern.CanMaximize), DetailViewModel.FromAutomationProperty("WindowVisualState", pattern.WindowVisualState), DetailViewModel.FromAutomationProperty("WindowInteractionState", pattern.WindowInteractionState) }; detailGroups.Add(new DetailGroupViewModel("Window Pattern", patternDetails)); } return(detailGroups); }