コード例 #1
0
 /// <summary>
 /// Replaces the element at the specified index.
 /// </summary>
 /// <param name="index">The zero-based index of the element to replace.</param>
 /// <param name="item">The new value for the element at the specified index. The value can be null for reference types.</param>
 /// <exception cref="T:System.ArgumentOutOfRangeException">
 ///     <paramref name="index"/> is less than zero.-or-<paramref name="index"/> is greater than <see cref="P:System.Collections.ObjectModel.Collection`1.Count"/>.</exception>
 protected override void SetItem(int index, EventBinding item)
 {
     EventBindingCollection.ValidateValue(item);
     if (item != this[index])
     {
         this[index].Source = null;
         base.SetItem(index, item);
         this[index].Source = this.SourceUIElement;
     }
 }
コード例 #2
0
        private static void OnEventBindingsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            UIElement uiElement = d as UIElement;

            if (uiElement != null)
            {
                EventBindingCollection oldEventBindingCollection = e.OldValue as EventBindingCollection;
                EventBindingCollection newEventBindingCollection = e.NewValue as EventBindingCollection;

                // Detach the old instance
                if (oldEventBindingCollection != null)
                {
                    oldEventBindingCollection.SourceUIElement = null;
                }

                // Attach the new instance
                if (newEventBindingCollection != null)
                {
                    newEventBindingCollection.SourceUIElement = uiElement;
                }
            }
        }
コード例 #3
0
 /// <summary>
 /// Sets the value of the <see cref="EventBindingsProperty"/> attached property for a specified <see cref="UIElement"/>.
 /// </summary>
 /// <param name="element">The element to which the attached property is written.</param>
 /// <param name="eventBindings">The event bindings.</param>
 public static void SetEventBindings(UIElement element, EventBindingCollection eventBindings)
 {
     element.SetValue(Extensions.EventBindingsProperty, eventBindings);
 }
コード例 #4
0
 /// <summary>
 /// Inserts an element into the <see cref="T:System.Collections.ObjectModel.Collection`1"/> at the specified index.
 /// </summary>
 /// <param name="index">The zero-based index at which <paramref name="item"/> should be inserted.</param>
 /// <param name="item">The object to insert. The value can be null for reference types.</param>
 /// <exception cref="T:System.ArgumentOutOfRangeException">
 ///     <paramref name="index"/> is less than zero.-or-<paramref name="index"/> is greater than <see cref="P:System.Collections.ObjectModel.Collection`1.Count"/>.</exception>
 protected override void InsertItem(int index, EventBinding item)
 {
     EventBindingCollection.ValidateValue(item);
     base.InsertItem(index, item);
     item.Source = this.SourceUIElement;
 }