internal void RaiseSelectionEvents(SelectionChangedEventArgs e)
        {
            if (base.ItemPeers.Count == 0)
            {
                base.RaiseAutomationEvent(AutomationEvents.SelectionPatternOnInvalidated);
                return;
            }
            Selector selector = (Selector)base.Owner;
            int      count    = selector._selectedItems.Count;
            int      count2   = e.AddedItems.Count;
            int      count3   = e.RemovedItems.Count;

            if (count == 1 && count2 == 1)
            {
                SelectorItemAutomationPeer selectorItemAutomationPeer = this.FindOrCreateItemAutomationPeer(selector._selectedItems[0].Item) as SelectorItemAutomationPeer;
                if (selectorItemAutomationPeer != null)
                {
                    selectorItemAutomationPeer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementSelected);
                    return;
                }
            }
            else
            {
                if (count2 + count3 > 20)
                {
                    base.RaiseAutomationEvent(AutomationEvents.SelectionPatternOnInvalidated);
                    return;
                }
                for (int i = 0; i < count2; i++)
                {
                    SelectorItemAutomationPeer selectorItemAutomationPeer2 = this.FindOrCreateItemAutomationPeer(e.AddedItems[i]) as SelectorItemAutomationPeer;
                    if (selectorItemAutomationPeer2 != null)
                    {
                        selectorItemAutomationPeer2.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementAddedToSelection);
                    }
                }
                for (int i = 0; i < count3; i++)
                {
                    SelectorItemAutomationPeer selectorItemAutomationPeer3 = this.FindOrCreateItemAutomationPeer(e.RemovedItems[i]) as SelectorItemAutomationPeer;
                    if (selectorItemAutomationPeer3 != null)
                    {
                        selectorItemAutomationPeer3.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection);
                    }
                }
            }
        }
Пример #2
0
        internal void RaiseSelectionEvents(SelectionChangedEventArgs e)
        {
            if (ItemPeers.Count == 0)
            {
                //  ItemPeers.Count == 0 if children were never fetched.
                //  in the case, when client probably is not interested in the details
                //  of selection changes. but we still want to notify client about it.
                this.RaiseAutomationEvent(AutomationEvents.SelectionPatternOnInvalidated);

                return;
            }

            Selector owner = (Selector)Owner;

            // These counters are bound to selection only numAdded = number of items just added and included in the current selection,
            // numRemoved = number of items just removed from the selection, numSelected = total number of items currently selected after addition and removal.
            int numSelected = owner._selectedItems.Count;
            int numAdded    = e.AddedItems.Count;
            int numRemoved  = e.RemovedItems.Count;

            if (numSelected == 1 && numAdded == 1)
            {
                SelectorItemAutomationPeer peer = FindOrCreateItemAutomationPeer(owner._selectedItems[0].Item) as SelectorItemAutomationPeer;
                if (peer != null)
                {
                    peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementSelected);
                }
            }
            else
            {
                // If more than InvalidateLimit element change their state then we invalidate the selection container
                // Otherwise we fire Add/Remove from selection events
                if (numAdded + numRemoved > AutomationInteropProvider.InvalidateLimit)
                {
                    this.RaiseAutomationEvent(AutomationEvents.SelectionPatternOnInvalidated);
                }
                else
                {
                    int i;

                    for (i = 0; i < numAdded; i++)
                    {
                        SelectorItemAutomationPeer peer = FindOrCreateItemAutomationPeer(e.AddedItems[i]) as SelectorItemAutomationPeer;

                        if (peer != null)
                        {
                            peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementAddedToSelection);
                        }
                    }

                    for (i = 0; i < numRemoved; i++)
                    {
                        SelectorItemAutomationPeer peer = FindOrCreateItemAutomationPeer(e.RemovedItems[i]) as SelectorItemAutomationPeer;

                        if (peer != null)
                        {
                            peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection);
                        }
                    }
                }
            }
        }