Ejemplo n.º 1
0
		public ListCollectionView (IList collection)
			: base (collection)
		{
			var interfaces = SourceCollection.GetType ().GetInterfaces ();
			foreach (var t in interfaces) {
				if (t.IsGenericType && t.GetGenericTypeDefinition () == typeof (IList<>)) {
					Type type = t.GetGenericArguments () [0];
					ItemConstructor = type.GetConstructor (Type.EmptyTypes);
				}
			}

			UpdateCanAddNewAndRemove ();
			filteredList = new ObservableList<object> ();
			RootGroup = new RootCollectionViewGroup (null, null, 0, false, SortDescriptions);
			CurrentPosition = -1;
			IsEmpty = ActiveList.Count == 0;
			MoveCurrentToPosition (0);

			if (SourceCollection is INotifyCollectionChanged)
				((INotifyCollectionChanged) SourceCollection).CollectionChanged += HandleSourceCollectionChanged;

			GroupDescriptions.CollectionChanged += (o, e) => Refresh ();
			((INotifyCollectionChanged) SortDescriptions).CollectionChanged += (o, e) => {
				if (IsAddingNew || IsEditingItem)
					throw new InvalidOperationException ("Cannot modify SortDescriptions while adding or editing an item");
				Refresh ();
			};

			filteredList.CollectionChanged += HandleFilteredListCollectionChanged;
			RootGroup.CollectionChanged += HandleRootGroupCollectionChanged;
		}
Ejemplo n.º 2
0
        public ListCollectionView(IList collection)
            : base(collection)
        {
            var interfaces = SourceCollection.GetType().GetInterfaces();

            foreach (var t in interfaces)
            {
                if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IList <>))
                {
                    Type type = t.GetGenericArguments() [0];
                    ItemConstructor = type.GetConstructor(Type.EmptyTypes);
                }
            }

            UpdateCanAddNewAndRemove();
            filteredList    = new ObservableList <object> ();
            RootGroup       = new RootCollectionViewGroup(SourceCollection, null, null, 0, false, SortDescriptions);
            CurrentPosition = -1;
            IsEmpty         = ActiveList.Count == 0;
            MoveCurrentToPosition(0);

            if (SourceCollection is INotifyCollectionChanged)
            {
                ((INotifyCollectionChanged)SourceCollection).CollectionChanged += HandleSourceCollectionChanged;
            }

            GroupDescriptions.CollectionChanged += (o, e) => Refresh();
            ((INotifyCollectionChanged)SortDescriptions).CollectionChanged += (o, e) => {
                if (IsAddingNew || IsEditingItem)
                {
                    throw new InvalidOperationException("Cannot modify SortDescriptions while adding or editing an item");
                }
                Refresh();
            };

            filteredList.CollectionChanged += HandleFilteredListCollectionChanged;
            RootGroup.CollectionChanged    += HandleRootGroupCollectionChanged;
        }