System.Windows.Controls.ItemContainerGenerator.OnOwnerItemsItemsChanged C# (CSharp) Метод

OnOwnerItemsItemsChanged() приватный Метод

private OnOwnerItemsItemsChanged ( object sender, NotifyCollectionChangedEventArgs e ) : void
sender object
e NotifyCollectionChangedEventArgs
Результат void
		internal void OnOwnerItemsItemsChanged (object sender, NotifyCollectionChangedEventArgs e)
		{
			int itemCount;
			int itemUICount;
			GeneratorPosition oldPosition = new GeneratorPosition(-1, 0);
			GeneratorPosition position;
			
			switch (e.Action) {
			case NotifyCollectionChangedAction.Add:
				if ((e.NewStartingIndex + 1) != Owner.Items.Count)
					MoveExistingItems (e.NewStartingIndex, 1);
				itemCount = 1;
				itemUICount = 0;
				position = GeneratorPositionFromIndex (e.NewStartingIndex);
				// Yes, this looks like a Silverlight Bug.
				position.Offset = 1;
				break;
			case NotifyCollectionChangedAction.Remove:
				itemCount = 1;
				itemUICount = RealizedElements.Contains (e.OldStartingIndex) ? 1 : 0;
				position = GeneratorPositionFromIndex (e.OldStartingIndex);
				if (itemUICount == 1)
					Remove (position, 1);
				MoveExistingItems (e.OldStartingIndex, -1);
				break;
			case NotifyCollectionChangedAction.Replace:
				if (!RealizedElements.Contains (e.NewStartingIndex))
					return;

				itemCount = 1;
				itemUICount = 1;
				position = GeneratorPositionFromIndex (e.NewStartingIndex);
				Remove (position, 1);

				bool fresh;
				var newPos = GeneratorPositionFromIndex (e.NewStartingIndex);
				using (StartAt (newPos, GeneratorDirection.Forward, true))
					PrepareItemContainer (GenerateNext (out fresh));
				break;
			case NotifyCollectionChangedAction.Reset:
				itemCount = e.OldItems == null ? 0 : e.OldItems.Count;
				itemUICount = RealizedElements.Count;
				position = new GeneratorPosition (-1, 0);
				RemoveAll ();
				break;
			default:
				Console.WriteLine ("*** Critical error in ItemContainerGenerator.OnOwnerItemsItemsChanged. NotifyCollectionChangedAction.{0} is not supported", e.Action);
				return;
			}
			
			ItemsChangedEventArgs args = new ItemsChangedEventArgs {
				Action = e.Action,
				ItemCount = itemCount,
				ItemUICount = itemUICount,
				OldPosition = oldPosition,
				Position = position
			};
			var h = ItemsChanged;
			if (h != null)
				h (this, args);
		}

Usage Example

Пример #1
0
        void InvokeItemsChanged(object o, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                SetLogicalParent(native, e.NewItems);
                break;

            case NotifyCollectionChangedAction.Remove:
                SetLogicalParent(IntPtr.Zero, e.OldItems);
                break;

            case NotifyCollectionChangedAction.Replace:
                SetLogicalParent(IntPtr.Zero, e.OldItems);
                SetLogicalParent(native, e.NewItems);
                break;
            }

            ItemContainerGenerator.OnOwnerItemsItemsChanged(o, e);
            if (!itemsIsDataBound)
            {
                OnItemsChanged(e);
            }
        }