|
using System;
using System.Collections.Generic;
namespace MsDesktopStackDemo.ViewModel.Events
{
#region Enums
/// <summary>
/// Describes the action that caused a CollectionChanging event.
/// </summary>
public enum NotifyCollectionChangingAction { Add, Remove, Replace, Move, Reset }
#endregion
#region Delegates
/// <summary>
/// Occurs before an item is added, removed, changed, moved, or the entire list is refreshed.
/// </summary>
/// <typeparam name="T">The type of elements in the collection.</typeparam>
/// <param name="sender">The object that raised the event.</param>
/// <param name="e">Information about the event.</param>
public delegate void CollectionChangingEventHandler<T>(object sender, NotifyCollectionChangingEventArgs<T> e);
#endregion
#region Event Args
public class NotifyCollectionChangingEventArgs<T> : EventArgs
{
#region Constructors
/// <summary>
/// Constructor with all arguments.
/// </summary>
/// <param name="action">The action that caused the event. </param>
/// <param name="oldItems">The list of items affected by a Replace, Remove, or Move action.</param>
/// <param name="newItems">The list of new items involved in the change.</param>
/// <param name="oldStartingIndex">The index at which a Move, Remove, or Replace action is occurring.</param>
/// <param name="newStartingIndex">The index at which the change is occurring.</param>
public NotifyCollectionChangingEventArgs(NotifyCollectionChangingAction action, IList<T> oldItems, IList<T> newItems, int oldStartingIndex, int newStartingIndex)
{
this.Action = action;
this.OldItems = oldItems;
this.NewItems = newItems;
this.OldStartingIndex = oldStartingIndex;
this.NewStartingIndex = newStartingIndex;
this.Cancel = false;
}
/// <summary>
/// Constructor that omits 'starting index' arguments.
/// </summary>
/// <param name="action">The action that caused the event. </param>
/// <param name="oldItems">The list of items affected by a Replace, Remove, or Move action.</param>
/// <param name="newItems">The list of new items involved in the change.</param>
public NotifyCollectionChangingEventArgs(NotifyCollectionChangingAction action, IList<T> oldItems, IList<T> newItems)
{
this.Action = action;
this.OldItems = oldItems;
this.NewItems = newItems;
this.OldStartingIndex = -1;
this.NewStartingIndex = -1;
this.Cancel = false;
}
#endregion
#region Properties
/// <summary>
/// Gets the action that caused the event.
/// </summary>
public NotifyCollectionChangingAction Action { get; private set; }
/// <summary>
/// Whether to cancel the pending change.
/// </summary>
/// <remarks>This property is set by an event subscriber. It enables
/// the subscriber to cancel the pending change.</remarks>
public bool Cancel { get; set; }
/// <summary>
/// Gets the list of new items involved in the change.
/// </summary>
public IList<T> NewItems { get; private set; }
/// <summary>
/// Gets the index at which the change is occurring.
/// </summary>
public int NewStartingIndex { get; set; }
/// <summary>
/// Gets the list of items affected by a Replace, Remove, or Move action.
/// </summary>
public IList<T> OldItems { get; private set; }
/// <summary>
/// Gets the index at which a Move, Remove, or Replace action is occurring.
/// </summary>
public int OldStartingIndex { get; set; }
#endregion
}
#endregion
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
David Veeneman is a financial planner and software developer. He is the author of "The Fortune in Your Future" (McGraw-Hill 1998). His company, Foresight Systems, develops planning and financial software.