コード例 #1
0
        protected SelectorItemAutomationPeer(UIElement owner) : base(owner)
        {
            ListBoxItem listboxitem = owner as ListBoxItem;

            if (listboxitem != null)
            {
                // SelectionItem Pattern Automation Events
                // - SelectionContainerProperty
                listboxitem.ParentSelectorChanged += (o, e) => {
                    AutomationPeer oldSelectorPeer = null;
                    AutomationPeer newSelectorPeer = null;

                    if (selector != null)
                    {
                        oldSelectorPeer
                            = FrameworkElementAutomationPeer.CreatePeerForElement(selector);
                    }
                    if (listboxitem.ParentSelector != null)
                    {
                        newSelectorPeer
                            = FrameworkElementAutomationPeer.CreatePeerForElement(listboxitem.ParentSelector);
                    }

                    RaisePropertyChangedEvent(SelectionItemPatternIdentifiers.SelectionContainerProperty,
                                              ProviderFromPeer(oldSelectorPeer),
                                              ProviderFromPeer(newSelectorPeer));
                    selector = listboxitem.ParentSelector;
                };
                selector = listboxitem.ParentSelector;
            }
        }
コード例 #2
0
        private AutomationPeer GetParentPeer(FrameworkElement element)
        {
            // We are returning parents of children already instantiated.
            if (element == null)
            {
                return(null);
            }

            FrameworkElement parent = VisualTreeHelper.GetParent(element) as FrameworkElement;

            if (parent == null)
            {
                return(null);
            }

            // Some parents don't return an Automation Peer (for example: Border or Panel subclasses)
            // We need to create the Peer because some Peers return children that don't
            // necesarily return this peer when calling GetParent
            // (for example: ListBox when Template is not null)
            AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(parent);

            if (peer == null)
            {
                return(GetParentPeer(parent));
            }
            else
            {
                return(peer);
            }
        }
コード例 #3
0
 private void SetScrollBarAutomationPeer(ScrollBar scrollbar, AutomationOrientation orientation)
 {
     if (scrollbar == null)
     {
         if (orientation == AutomationOrientation.Horizontal)
         {
             hScrollbarPeer = null;
         }
         else
         {
             vScrollbarPeer = null;
         }
     }
     else
     {
         if (orientation == AutomationOrientation.Horizontal)
         {
             hScrollbarPeer
                 = FrameworkElementAutomationPeer.CreatePeerForElement(scrollbar) as ScrollBarAutomationPeer;
         }
         else
         {
             vScrollbarPeer
                 = FrameworkElementAutomationPeer.CreatePeerForElement(scrollbar) as ScrollBarAutomationPeer;
         }
     }
 }
コード例 #4
0
        protected override List <AutomationPeer> GetChildrenCore()
        {
            ItemsControl itemsControl = (ItemsControl)Owner;

            if (itemsControl.Items.Count == 0)
            {
                return(null);
            }

            List <AutomationPeer> children = new List <AutomationPeer> ();

            for (int index = 0; index < itemsControl.Items.Count; index++)
            {
                UIElement item = GetItem(itemsControl, index);
                if (item == null)
                {
                    return(null);
                }

                AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(item);
                if (peer != null)
                {
                    children.Add(peer);
                }
            }

            return(children);
        }
コード例 #5
0
        protected override List <AutomationPeer> GetChildrenCore()
        {
            TreeView owner = OwnerTreeView;

            ItemCollection items = owner.Items;

            if (items.Count <= 0)
            {
                return(null);
            }

            List <AutomationPeer> peers = new List <AutomationPeer>(items.Count);

            for (int i = 0; i < items.Count; i++)
            {
                TreeViewItem element = owner.ItemContainerGenerator.ContainerFromIndex(i) as TreeViewItem;
                if (element != null)
                {
                    peers.Add(
                        FrameworkElementAutomationPeer.FromElement(element) ??
                        FrameworkElementAutomationPeer.CreatePeerForElement(element));
                }
            }

            return(peers);
        }
コード例 #6
0
 /// <summary>
 /// Returns a System.Windows.Point that represents the clickable space that is
 /// on the System.Windows.UIElement that is associated with this System.Windows.Automation.Peers.FrameworkElementAutomationPeer.
 /// This method is called by System.Windows.Automation.Peers.AutomationPeer.GetClickablePoint().
 /// </summary>
 /// <returns>The System.Windows.Point on the element that allows a click.</returns>
 protected override Point GetClickablePointCore()
 {
     // Return the clickable point of the page number TextBox when present.
     switch (this.OwningDataPager.DisplayMode)
     {
     case PagerDisplayMode.FirstLastPreviousNext:
     case PagerDisplayMode.PreviousNext:
         if (this.OwningDataPager.CurrentPageTextBox != null)
         {
             AutomationPeer peer = FrameworkElementAutomationPeer.FromElement(this.OwningDataPager.CurrentPageTextBox);
             if (peer != null)
             {
                 peer.InvalidatePeer();
             }
             else
             {
                 peer = FrameworkElementAutomationPeer.CreatePeerForElement(this.OwningDataPager.CurrentPageTextBox);
             }
             if (peer != null)
             {
                 return(peer.GetClickablePoint());
             }
         }
         break;
     }
     return(base.GetClickablePointCore());
 }
コード例 #7
0
        /// <summary>
        /// Provides initialization for base class values when called by the constructor
        /// of a derived class.
        /// </summary>
        /// <param name="item">The item to create the automation peer for.</param>
        /// <returns>The item automation peer.</returns>
        protected override ItemAutomationPeer CreateItemAutomationPeer(object item)
        {
            ItemAutomationPeer peer    = null;
            UIElement          element = item as UIElement;

            if (element != null)
            {
                peer = FrameworkElementAutomationPeer.CreatePeerForElement(element) as ItemAutomationPeer;
            }
            return(peer);
        }
コード例 #8
0
        private AutomationPeer GetSelectedAutomationPeer()
        {
            Selector selector = (Selector)Owner;

            if (selector.SelectedIndex == -1)
            {
                return(null);
            }

            return(FrameworkElementAutomationPeer.CreatePeerForElement((UIElement)selector.ItemContainerGenerator.ContainerFromIndex(selector.SelectedIndex)));
        }
コード例 #9
0
        protected override AutomationPeer GetLabeledByCore()
        {
            UIElement labeledBy = owner.GetValue(AutomationProperties.LabeledByProperty) as UIElement;

            if (labeledBy != null)
            {
                return(FrameworkElementAutomationPeer.CreatePeerForElement(labeledBy));
            }
            else
            {
                return(null);
            }
        }
コード例 #10
0
 IRawElementProviderSimple[] ISelectionProvider.GetSelection()
 {
     if (this.OwningRow != null &&
         this.OwningDataGrid.DisplayData.IsRowDisplayed(this.OwningRow.Index) &&
         this.OwningDataGrid.CurrentRowIndex == this.OwningRow.Index)
     {
         DataGridCell   cell = this.OwningRow.Cells[this.OwningRow.OwningGrid.CurrentColumnIndex];
         AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(cell);
         if (peer != null)
         {
             return(new IRawElementProviderSimple[] { ProviderFromPeer(peer) });
         }
     }
     return(null);
 }
コード例 #11
0
 IRawElementProviderSimple[] ISelectionProvider.GetSelection()
 {
     if (this.OwningRow != null &&
         this.OwningDataGrid.IsSlotVisible(this.OwningRow.Slot) &&
         this.OwningDataGrid.CurrentSlot == this.OwningRow.Slot)
     {
         DataGridCell   cell = this.OwningRow.Cells[this.OwningRow.OwningGrid.CurrentColumnIndex];
         AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(cell);
         if (peer != null)
         {
             return(new IRawElementProviderSimple[] { ProviderFromPeer(peer) });
         }
     }
     return(null);
 }
コード例 #12
0
        public override object GetPattern(PatternInterface patternInterface)
        {
            if (patternInterface == PatternInterface.Scroll)
            {
                ScrollViewer patternImplementor = ScrollPatternImplementor;
                if (patternImplementor != null)
                {
                    AutomationPeer peer
                        = FrameworkElementAutomationPeer.CreatePeerForElement(patternImplementor);
                    return(peer.GetPattern(patternInterface));
                }
                return(null);
            }

            return(base.GetPattern(patternInterface));
        }
コード例 #13
0
        /// <summary>
        /// Gets the table item's column headers.
        /// </summary>
        /// <returns>The table item's column headers</returns>
        IRawElementProviderSimple[] ITableItemProvider.GetColumnHeaderItems()
        {
            if (IsDayButton && OwningButton != null)
            {
                if (this.OwningCalendar != null && this.OwningCalendarProvider != null)
                {
                    IRawElementProviderSimple[] headers = ((ITableProvider)FrameworkElementAutomationPeer.CreatePeerForElement(this.OwningCalendar)).GetColumnHeaders();

                    if (headers != null)
                    {
                        int column = ((IGridItemProvider)this).Column;
                        return(new IRawElementProviderSimple[] { headers[column] });
                    }
                }
            }
            return(null);
        }
コード例 #14
0
        /// <summary>
        /// AutomationPeer for an item in a DataGrid
        /// </summary>
        public DataGridItemAutomationPeer(object item, DataGrid dataGrid)
            : base(dataGrid)
        {
            if (item == null)
            {
                //

                throw new ElementNotAvailableException();
            }
            if (dataGrid == null)
            {
                //

                throw new ElementNotAvailableException();
            }

            _item = item;
            _dataGridAutomationPeer = FrameworkElementAutomationPeer.CreatePeerForElement(dataGrid);
        }
コード例 #15
0
        protected override List <AutomationPeer> GetChildrenCore()
        {
            List <AutomationPeer>          children = base.GetChildrenCore();
            DataGridColumnHeadersPresenter columnsHeaderPresenter = this.OwningDataGrid.ColumnHeadersPresenter;

            // Add ColumnsHeaderPresenter if it is visible
            if (columnsHeaderPresenter != null && columnsHeaderPresenter.IsVisible)
            {
                AutomationPeer columnsHeaderPresenterPeer = FrameworkElementAutomationPeer.CreatePeerForElement(columnsHeaderPresenter);
                if (columnsHeaderPresenterPeer != null)
                {
                    if (children == null)
                    {
                        children = new List <AutomationPeer>(1);
                    }
                    children.Insert(0, columnsHeaderPresenterPeer);
                }
            }

            return(children);
        }
コード例 #16
0
        /// <summary>
        /// Retrieves a UI automation provider for each child element that is
        /// selected.
        /// </summary>
        /// <returns>An array of UI automation providers.</returns>
        /// <remarks>
        /// This API supports the .NET Framework infrastructure and is not
        /// intended to be used directly from your code.
        /// </remarks>
        IRawElementProviderSimple[] ISelectionProvider.GetSelection()
        {
            if (OwnerAutoCompleteBox.SelectionAdapter != null)
            {
                object selectedItem = OwnerAutoCompleteBox.SelectionAdapter.SelectedItem;
                if (selectedItem != null)
                {
                    UIElement uie = selectedItem as UIElement;
                    if (uie != null)
                    {
                        AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(uie);
                        if (peer != null)
                        {
                            return(new IRawElementProviderSimple[] { ProviderFromPeer(peer) });
                        }
                    }
                }
            }

            return(new IRawElementProviderSimple[] { });
        }
コード例 #17
0
        /// <summary>
        /// Gets a control pattern for the
        /// <see cref="T:System.Windows.Controls.TreeView" /> that is associated
        /// with this
        /// <see cref="T:System.Windows.Automation.Peers.TreeViewAutomationPeer" />.
        /// </summary>
        /// <param name="patternInterface">
        /// One of the enumeration values that indicates the control pattern.
        /// </param>
        /// <returns>
        /// The object that implements the pattern interface, or null if the
        /// specified pattern interface is not implemented by this peer.
        /// </returns>
        public override object GetPattern(PatternInterface patternInterface)
        {
            if (patternInterface == PatternInterface.Selection)
            {
                return this;
            }
            else if (patternInterface == PatternInterface.Scroll)
            {
                ScrollViewer scroll = OwnerTreeView.ItemsControlHelper.ScrollHost;
                if (scroll != null)
                {
                    AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(scroll);
                    IScrollProvider provider = peer as IScrollProvider;
                    if (provider != null)
                    {
                        peer.EventsSource = this;
                        return provider;
                    }
                }
            }

            return null;
        }
        /// <summary>
        /// AutomationPeer for a group of items in a DataGrid
        /// </summary>
        public DataGridGroupItemAutomationPeer(CollectionViewGroup group, DataGrid dataGrid)
            : base(dataGrid)
        {
            if (group == null)
            {
                //



                throw new ElementNotAvailableException();
            }
            if (dataGrid == null)
            {
                //



                throw new ElementNotAvailableException();
            }

            _group = group;
            _dataGridAutomationPeer = FrameworkElementAutomationPeer.CreatePeerForElement(dataGrid);
        }
コード例 #19
0
        internal static List <AutomationPeer> GetChildrenRecursively(UIElement uielement)
        {
            List <AutomationPeer> children = new List <AutomationPeer> ();
            int childrenCount = VisualTreeHelper.GetChildrenCount(uielement);

            for (int child = 0; child < childrenCount; child++)
            {
                UIElement element = VisualTreeHelper.GetChild(uielement, child) as UIElement;
                if (element == null)
                {
                    continue;
                }

                AutomationPeer peer
                    = FrameworkElementAutomationPeer.CreatePeerForElement(element);
                if (peer != null)
                {
                    children.Add(peer);
                }
                else
                {
                    List <AutomationPeer> returnedChildren
                        = GetChildrenRecursively(element);
                    if (returnedChildren != null)
                    {
                        children.AddRange(returnedChildren);
                    }
                }
            }

            if (children.Count == 0)
            {
                return(null);
            }

            return(children);
        }
コード例 #20
0
        protected override string GetNameCore()
        {
            ButtonBase buttonBase = Owner as ButtonBase;

            // Only when Content is TextBlock TextBlock.Name is returned
            string name = buttonBase.Content as string;

            if (name == null)
            {
                TextBlock textblock = buttonBase.Content as TextBlock;
                if (textblock == null)
                {
                    name = string.Empty;
                }
                else
                {
                    AutomationPeer peer
                         = FrameworkElementAutomationPeer.CreatePeerForElement(textblock);
                    name = peer.GetName();
                }
            }

            return(buttonBase.GetValue(AutomationProperties.NameProperty) as string ?? name);
        }
コード例 #21
0
        protected override List <AutomationPeer> GetChildrenCore()
        {
            List <AutomationPeer> children = new List <AutomationPeer>();
            AutoCompleteBox       owner    = OwnerAutoCompleteBox;

            // TextBox part.
            TextBox textBox = owner.TextBox;

            if (textBox != null)
            {
                AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(textBox);
                if (peer != null)
                {
                    children.Insert(0, peer);
                }
            }

            // Include SelectionAdapter's children.
            if (owner.SelectionAdapter != null)
            {
                AutomationPeer selectionAdapterPeer = owner.SelectionAdapter.CreateAutomationPeer();
                if (selectionAdapterPeer != null)
                {
                    List <AutomationPeer> listChildren = selectionAdapterPeer.GetChildren();
                    if (listChildren != null)
                    {
                        foreach (AutomationPeer child in listChildren)
                        {
                            children.Add(child);
                        }
                    }
                }
            }

            return(children);
        }
コード例 #22
0
        protected override List <AutomationPeer> GetChildrenCore()
        {
            if (OwningCalendar.MonthControl == null)
            {
                return(null);
            }

            List <AutomationPeer> peers = new List <AutomationPeer>();
            Dictionary <DateTimeCalendarModePair, DateTimeAutomationPeer> newChildren = new Dictionary <DateTimeCalendarModePair, DateTimeAutomationPeer>();

            // Step 1: Add previous, header and next buttons
            AutomationPeer buttonPeer;

            buttonPeer = FrameworkElementAutomationPeer.CreatePeerForElement(OwningCalendar.MonthControl.PreviousButton);
            if (buttonPeer != null)
            {
                peers.Add(buttonPeer);
            }
            buttonPeer = FrameworkElementAutomationPeer.CreatePeerForElement(OwningCalendar.MonthControl.HeaderButton);
            if (buttonPeer != null)
            {
                peers.Add(buttonPeer);
            }
            buttonPeer = FrameworkElementAutomationPeer.CreatePeerForElement(OwningCalendar.MonthControl.NextButton);
            if (buttonPeer != null)
            {
                peers.Add(buttonPeer);
            }

            // Step 2: Add Calendar Buttons depending on the Calendar.DisplayMode
            DateTime date;
            DateTimeAutomationPeer peer;

            foreach (UIElement child in this.OwningGrid.Children)
            {
                int childRow = (int)child.GetValue(Grid.RowProperty);
                // first row is day titles
                if (OwningCalendar.DisplayMode == CalendarMode.Month && childRow == 0)
                {
                    AutomationPeer dayTitlePeer = UIElementAutomationPeer.CreatePeerForElement(child);
                    if (dayTitlePeer != null)
                    {
                        peers.Add(dayTitlePeer);
                    }
                }
                else
                {
                    Button owningButton = child as Button;
                    if (owningButton != null && owningButton.DataContext is DateTime)
                    {
                        date = (DateTime)owningButton.DataContext;
                        peer = GetOrCreateDateTimeAutomationPeer(date, OwningCalendar.DisplayMode, /*addParentInfo*/ false);
                        peers.Add(peer);

                        DateTimeCalendarModePair key = new DateTimeCalendarModePair(date, OwningCalendar.DisplayMode);
                        newChildren.Add(key, peer);
                    }
                }
            }

            DateTimePeers = newChildren;
            return(peers);
        }
コード例 #23
0
        public FrameworkElementAutomationPeer(FrameworkElement owner)
        {
            if (owner == null)
            {
                throw new ArgumentNullException("owner");
            }
            this.owner          = owner;
            isKeyboardFocusable = null;

            // Default Automation events
            owner.SizeChanged += (o, s) => {
                Point location = GetLocation(owner);
                RaisePropertyChangedEvent(AutomationElementIdentifiers.BoundingRectangleProperty,
                                          new Rect(0, 0, s.PreviousSize.Width, s.PreviousSize.Height),
                                          new Rect(location.X, location.Y, s.NewSize.Width, s.NewSize.Height));
            };
            owner.UIAVisibilityChanged += (o, e) => {
                IAutomationCacheProperty cachedProperty
                    = GetCachedProperty(AutomationElementIdentifiers.BoundingRectangleProperty);
                Rect newValue = GetBoundingRectangle();
                RaisePropertyChangedEvent(AutomationElementIdentifiers.BoundingRectangleProperty,
                                          cachedProperty.OldValue,
                                          newValue);

                RaiseIsKeyboardFocusableEvent();

                bool isOffscreen = IsOffscreen();
                RaisePropertyChangedEvent(AutomationElementIdentifiers.IsOffscreenProperty,
                                          !isOffscreen,
                                          isOffscreen);
            };

            Control control = owner as Control;

            if (control != null)
            {
                control.IsEnabledChanged += (o, e) => {
                    RaisePropertyChangedEvent(AutomationElementIdentifiers.IsEnabledProperty,
                                              e.OldValue,
                                              e.NewValue);

                    RaiseIsKeyboardFocusableEvent();
                };
                control.UIAIsTabStopChanged += (o, e) => {
                    RaiseIsKeyboardFocusableEvent();
                };

                // StructureChanged
                ContentControl contentControl = control as ContentControl;
                if (contentControl != null)
                {
                    contentControl.UIAContentChanged += OnContentChanged;
                    AddItemsChangedToPanel(contentControl.Content);
                }
            }

            // SWA.AutomationProperties events
            owner.AcceleratorKeyChanged += (o, e) => {
                RaisePropertyChangedEvent(AutomationElementIdentifiers.AcceleratorKeyProperty,
                                          e.OldValue,
                                          e.NewValue);
            };
            owner.AccessKeyChanged += (o, e) => {
                RaisePropertyChangedEvent(AutomationElementIdentifiers.AccessKeyProperty,
                                          e.OldValue,
                                          e.NewValue);
            };
            owner.AutomationIdChanged += (o, e) => {
                RaisePropertyChangedEvent(AutomationElementIdentifiers.AutomationIdProperty,
                                          e.OldValue,
                                          e.NewValue);
            };
            owner.HelpTextChanged += (o, e) => {
                RaisePropertyChangedEvent(AutomationElementIdentifiers.HelpTextProperty,
                                          e.OldValue,
                                          e.NewValue);
            };
            owner.IsRequiredForFormChanged += (o, e) => {
                RaisePropertyChangedEvent(AutomationElementIdentifiers.IsRequiredForFormProperty,
                                          e.OldValue,
                                          e.NewValue);
            };
            owner.ItemStatusChanged += (o, e) => {
                RaisePropertyChangedEvent(AutomationElementIdentifiers.ItemStatusProperty,
                                          e.OldValue,
                                          e.NewValue);
            };
            owner.ItemTypeChanged += (o, e) => {
                RaisePropertyChangedEvent(AutomationElementIdentifiers.ItemTypeProperty,
                                          e.OldValue,
                                          e.NewValue);
            };
            // LabeledBy and Name properties are "special" because they somehow depend on each other.
            owner.LabeledByChanged += (o, e) => {
                RaisePropertyChangedEvent(AutomationElementIdentifiers.LabeledByProperty,
                                          e.OldValue,
                                          e.NewValue);
                // Name property
                UIElement labeledByOld = e.OldValue as UIElement;
                if (labeledByOld != null)
                {
                    FrameworkElementAutomationPeer peer
                        = FrameworkElementAutomationPeer.CreatePeerForElement(labeledByOld) as FrameworkElementAutomationPeer;
                    if (peer != null)
                    {
                        peer.NameChanged -= LabeledBy_NameChanged;
                    }
                }
                UIElement labeledByNew = e.NewValue as UIElement;
                if (labeledByNew != null)
                {
                    FrameworkElementAutomationPeer peer
                        = FrameworkElementAutomationPeer.CreatePeerForElement(labeledByNew) as FrameworkElementAutomationPeer;
                    if (peer != null)
                    {
                        peer.NameChanged += LabeledBy_NameChanged;
                    }
                }
                RaiseNameChanged();
            };
            owner.NameChanged += (o, e) => RaiseNameChanged();
        }