예제 #1
0
        // DON'T USE THIS SNIPPET -- PROBABLY NOT RAISING CORRECT EVENTS

        // <Snippet118>
        /// <summary>
        /// Selects an item in the myItems collection.
        /// </summary>
        /// <param name="index">Index of the selected item.</param>
        /// <remarks>
        /// This is a single-selection list whose current selection is stored
        /// internally in mySelection.
        /// MyListItem is the provider class for list items.
        /// </remarks>
        public void Select(int index)
        {
            if (index >= myItems.Count)
            {
                throw new ArgumentOutOfRangeException();
            }
            else if (index < 0)
            {
                mySelection = -1;
                return;
            }
            else
            // If within range, clear the Selected property on the current item
            // and set it on the new item.
            {
                MyListItem newItem;
                MyListItem oldItem = null;

                // Deselect old item, if there is one; list might not be initialized.
                if (mySelection >= 0)
                {
                    oldItem          = myItems[mySelection] as MyListItem;
                    oldItem.Selected = false;
                }
                mySelection      = index;
                newItem          = myItems[mySelection] as MyListItem;
                newItem.Selected = true;
                // Raise events that clients can receive.
                if (AutomationInteropProvider.ClientsAreListening)
                {
                    // Generic event for selection made.
                    AutomationEventArgs args = new AutomationEventArgs(SelectionItemPatternIdentifiers.ElementSelectedEvent);
                    AutomationInteropProvider.RaiseAutomationEvent(SelectionItemPattern.ElementSelectedEvent,
                                                                   (IRawElementProviderSimple)myItems[mySelection], args);

                    // Property-changed event for old item's Selection property.
                    AutomationPropertyChangedEventArgs propArgs;
                    if (oldItem != null)
                    {
                        propArgs = new AutomationPropertyChangedEventArgs(
                            SelectionItemPatternIdentifiers.IsSelectedProperty, true, false);
                        AutomationInteropProvider.RaiseAutomationPropertyChangedEvent(oldItem, propArgs);
                    }

                    // Property-changed event for new item's Selection property.
                    propArgs = new AutomationPropertyChangedEventArgs(
                        SelectionItemPatternIdentifiers.IsSelectedProperty, false, true);
                    AutomationInteropProvider.RaiseAutomationPropertyChangedEvent(newItem, propArgs);
                }
            }
        }
예제 #2
0
// </Snippet123>

        /// <summary>
        /// Add an item to the list.
        /// </summary>
        /// <param name="text">Item to add.</param>
        /// <returns>Index of the added item.</returns>
        public int Add(String text)
        {
            // Dynamically resize the control. To keep things simple for this example,
            // it is assumed that there will be no need for scrolling.
            if (myItems.Count > 0)
            {
                this.Height += itemHeight;
            }

            // Initialize the selection.
            if (mySelection < 0)
            {
                mySelection = 0;
            }

            // Create the item and add it.
            int itemTop   = DisplayRectangle.Top + (itemHeight * myItems.Count) + 1;
            int itemLeft  = DisplayRectangle.Left + 1;
            int itemWidth = DisplayRectangle.Width - 2;

            MyListItem listItem = new MyListItem(this, myItems, text, new Rectangle(itemTop, itemLeft, itemWidth, itemHeight));

            return(myItems.Add(listItem));
        }
예제 #3
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="listItem">Item for which this pattern is implemented.</param>
 /// <param name="parent">List that contains the item.</param>
 public ListItemPattern(MyListItem listItem, ParentList parent)
 {
     myListItem    = listItem;
     parentList    = parent;
     selectedItems = new ArrayList();
 }