Пример #1
0
        /// <summary>
        /// A virtual function that is called when the selection is changed. Default behavior
        /// is to raise a SelectionChangedEvent
        /// </summary>
        /// <param name="e">The inputs for this event. Can be raised (default behavior) or processed
        ///   in some other way.</param>
        protected override void OnSelectionChanged(SelectionChangedEventArgs e)
        {
            base.OnSelectionChanged(e);

            // In a single selection mode we want to move anchor to the selected element
            if (SelectionMode == SelectionMode.Single)
            {
                ItemInfo    info     = InternalSelectedInfo;
                ListBoxItem listItem = (info != null) ? info.Container as ListBoxItem : null;

                if (listItem != null)
                {
                    UpdateAnchorAndActionItem(info);
                }
            }

            if (AutomationPeer.ListenerExists(AutomationEvents.SelectionPatternOnInvalidated) ||
                AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementSelected) ||
                AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementAddedToSelection) ||
                AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection))
            {
                ListBoxAutomationPeer peer = UIElementAutomationPeer.CreatePeerForElement(this) as ListBoxAutomationPeer;
                if (peer != null)
                {
                    peer.RaiseSelectionEvents(e);
                }
            }
        }
 /// <summary>Responds to a list box selection change by raising a <see cref="E:System.Windows.Controls.Primitives.Selector.SelectionChanged" /> event. </summary>
 /// <param name="e">Provides data for <see cref="T:System.Windows.Controls.SelectionChangedEventArgs" />. </param>
 // Token: 0x06005130 RID: 20784 RVA: 0x0016C274 File Offset: 0x0016A474
 protected override void OnSelectionChanged(SelectionChangedEventArgs e)
 {
     base.OnSelectionChanged(e);
     if (this.SelectionMode == SelectionMode.Single)
     {
         ItemsControl.ItemInfo internalSelectedInfo = base.InternalSelectedInfo;
         ListBoxItem           listBoxItem          = (internalSelectedInfo != null) ? (internalSelectedInfo.Container as ListBoxItem) : null;
         if (listBoxItem != null)
         {
             this.UpdateAnchorAndActionItem(internalSelectedInfo);
         }
     }
     if (AutomationPeer.ListenerExists(AutomationEvents.SelectionPatternOnInvalidated) || AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementSelected) || AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementAddedToSelection) || AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection))
     {
         ListBoxAutomationPeer listBoxAutomationPeer = UIElementAutomationPeer.CreatePeerForElement(this) as ListBoxAutomationPeer;
         if (listBoxAutomationPeer != null)
         {
             listBoxAutomationPeer.RaiseSelectionEvents(e);
         }
     }
 }