Ejemplo n.º 1
0
 public ObservableList(IEnumerable <T> collection)
 {
     list = new List <T>(collection);
     //foreach (INotifyPropertyChanged item in collection)
     foreach (T item in collection)
     {
         //item.PropertyChanged += new PropertyChangedEventHandler(OnPropertyChangedHandler);
         T oldValue = null;
         ObservableItemsTools.SetNewObservedValue <T>(item, ref oldValue, OnPropertyChangedHandler);
     }
 }
Ejemplo n.º 2
0
        // Summary:
        //     Gets or sets the element at the specified index.
        //
        // Parameters:
        //   index:
        //     The zero-based index of the element to get or set.
        //
        // Returns:
        //     The element at the specified index.
        //
        // Exceptions:
        //   System.ArgumentOutOfRangeException:
        //     index is not a valid index in the System.Collections.IList.
        //
        //   System.NotSupportedException:
        //     The property is set and the System.Collections.IList is read-only.
        object IList.this[int index]
        {
            get
            {
                return(((IList)list)[index]);
            }

            set
            {
                T oldValue = list[index];
                ObservableItemsTools.SetNewObservedValue <T>(value as T, ref oldValue, OnPropertyChangedHandler);
                ((IList)list)[index] = value;
            }
        }
Ejemplo n.º 3
0
        //
        // Summary:
        //     Removes the first occurrence of a specific object from the System.Collections.IList.
        //
        // Parameters:
        //   value:
        //     The object to remove from the System.Collections.IList.
        //
        // Exceptions:
        //   System.NotSupportedException:
        //     The System.Collections.IList is read-only.-or- The System.Collections.IList
        //     has a fixed size.
        void IList.Remove(object value)
        {
            T oldValue = value as T;

            ObservableItemsTools.SetNewObservedValue <T>(null, ref oldValue, OnPropertyChangedHandler);
            ((IList)list).Remove(value);

#if SILVERLIGHT
            NotifyCollectionChangedEventArgs arg = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset);
#else
            NotifyCollectionChangedEventArgs arg = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, value);
#endif

            OnCollectionChanged(arg);
        }
Ejemplo n.º 4
0
        //
        // Summary:
        //     Inserts an item to the System.Collections.IList at the specified index.
        //
        // Parameters:
        //   index:
        //     The zero-based index at which value should be inserted.
        //
        //   value:
        //     The object to insert into the System.Collections.IList.
        //
        // Exceptions:
        //   System.ArgumentOutOfRangeException:
        //     index is not a valid index in the System.Collections.IList.
        //
        //   System.NotSupportedException:
        //     The System.Collections.IList is read-only.-or- The System.Collections.IList
        //     has a fixed size.
        //
        //   System.NullReferenceException:
        //     value is null reference in the System.Collections.IList.
        void IList.Insert(int index, object value)
        {
            T oldValue = null;

            ObservableItemsTools.SetNewObservedValue <T>(value as T, ref oldValue, OnPropertyChangedHandler);
            ((IList)list).Insert(index, value);

#if SILVERLIGHT
            NotifyCollectionChangedEventArgs arg = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset);
#else
            NotifyCollectionChangedEventArgs arg = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, value);
#endif

            OnCollectionChanged(arg);
        }
Ejemplo n.º 5
0
        // Summary:
        //     Adds an item to the System.Collections.Generic.ICollection<T>.
        //
        // Parameters:
        //   item:
        //     The object to add to the System.Collections.Generic.ICollection<T>.
        //
        // Exceptions:
        //   System.NotSupportedException:
        //     The System.Collections.Generic.ICollection<T> is read-only.
        public void Add(T item)
        {
            list.Add(item);
            T oldValue = null;

            ObservableItemsTools.SetNewObservedValue <T>(item, ref oldValue, OnPropertyChangedHandler);

#if SILVERLIGHT
            NotifyCollectionChangedEventArgs arg = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset);
#else
            NotifyCollectionChangedEventArgs arg = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item);
#endif

            OnCollectionChanged(arg);
        }
Ejemplo n.º 6
0
        //
        // Summary:
        //     Removes the System.Collections.Generic.IList<T> item at the specified index.
        //
        // Parameters:
        //   index:
        //     The zero-based index of the item to remove.
        //
        // Exceptions:
        //   System.ArgumentOutOfRangeException:
        //     index is not a valid index in the System.Collections.Generic.IList<T>.
        //
        //   System.NotSupportedException:
        //     The System.Collections.Generic.IList<T> is read-only.
        public void RemoveAt(int index)
        {
            T oldValue     = list[index];
            T removedValue = oldValue;

            ObservableItemsTools.SetNewObservedValue <T>(null, ref removedValue, OnPropertyChangedHandler);
            list.RemoveAt(index);

#if SILVERLIGHT
            NotifyCollectionChangedEventArgs arg = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset);
#else
            NotifyCollectionChangedEventArgs arg = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, oldValue);
#endif

            OnCollectionChanged(arg);
        }
Ejemplo n.º 7
0
        //
        // Summary:
        //     Removes all items from the System.Collections.Generic.ICollection<T>.
        //
        // Exceptions:
        //   System.NotSupportedException:
        //     The System.Collections.Generic.ICollection<T> is read-only.
        public void Clear()
        {
            int count  = list.Count;
            T   newVal = null;

            foreach (T item in list)
            {
                T it = item;
                ObservableItemsTools.SetNewObservedValue <T>(newVal, ref it, OnPropertyChangedHandler);
                //item.PropertyChanged -= new PropertyChangedEventHandler(OnPropertyChangedHandler);
            }

            list.Clear();
            if (count > 0)
            {
                NotifyCollectionChangedEventArgs arg = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset);
                OnCollectionChanged(arg);
            }
        }
Ejemplo n.º 8
0
        //
        // Summary:
        //     Removes the first occurrence of a specific object from the System.Collections.Generic.ICollection<T>.
        //
        // Parameters:
        //   item:
        //     The object to remove from the System.Collections.Generic.ICollection<T>.
        //
        // Returns:
        //     true if item was successfully removed from the System.Collections.Generic.ICollection<T>;
        //     otherwise, false. This method also returns false if item is not found in
        //     the original System.Collections.Generic.ICollection<T>.
        //
        // Exceptions:
        //   System.NotSupportedException:
        //     The System.Collections.Generic.ICollection<T> is read-only.
        public bool Remove(T item)
        {
            T removedItem = item;

            ObservableItemsTools.SetNewObservedValue <T>(null, ref removedItem, OnPropertyChangedHandler);
            bool retval = list.Remove(item);

            if (retval)
            {
#if SILVERLIGHT
                NotifyCollectionChangedEventArgs arg = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset);
#else
                NotifyCollectionChangedEventArgs arg = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item);
#endif

                OnCollectionChanged(arg);
            }

            return(retval);
        }
Ejemplo n.º 9
0
        //
        // Summary:
        //     Adds the elements of the specified collection to the end of the System.Collections.CI.Common.ObservableList<T>.
        //
        // Parameters:
        //   collection:
        //     The collection whose elements should be added to the end of the System.Collections.CI.Common.ObservableList<T>.
        //     The collection itself cannot be null, but it can contain elements that are
        //     null, if type T is a reference type.
        //
        // Exceptions:
        //   System.ArgumentNullException:
        //     collection is null.
        public void AddRange(IEnumerable <T> collection)
        {
            if (collection == null)
            {
                throw new ArgumentNullException();
            }

            list.AddRange(collection);
            T oldValue = null;

            foreach (var item in collection)
            {
                oldValue = null;
                ObservableItemsTools.SetNewObservedValue <T>(item, ref oldValue, OnPropertyChangedHandler);
            }

            var arg = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset);

            OnCollectionChanged(arg);
        }
Ejemplo n.º 10
0
        // Summary:
        //     Gets or sets the element at the specified index.
        //
        // Parameters:
        //   index:
        //     The zero-based index of the element to get or set.
        //
        // Returns:
        //     The element at the specified index.
        //
        // Exceptions:
        //   System.ArgumentOutOfRangeException:
        //     index is not a valid index in the System.Collections.Generic.IList<T>.
        //
        //   System.NotSupportedException:
        //     The property is set and the System.Collections.Generic.IList<T> is read-only.
        public T this[int index]
        {
            get
            {
                return(list[index]);
            }
            set
            {
                T oldValue = list[index];
                ObservableItemsTools.SetNewObservedValue <T>(value, ref oldValue, OnPropertyChangedHandler);
                list[index] = value;

#if SILVERLIGHT
                NotifyCollectionChangedEventArgs arg = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset);
#else
                NotifyCollectionChangedEventArgs arg = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, value, oldValue);
#endif

                OnCollectionChanged(arg);
            }
        }