Click here to Skip to main content
15,885,278 members
Articles / Programming Languages / C#

INotifyPropertyChanged and beyond - Part II

Rate me:
Please Sign up or sign in to vote.
4.97/5 (16 votes)
30 May 2007CPOL11 min read 69.8K   707   71  
Add support for event suppression and event propagation
using System;
using System.ComponentModel;

namespace NotifyTest {
	/// <summary>
	/// This class extends <see cref="T:PropertyNotificationEventArgs"/> and
	/// allows for cancelling of the associated event.
	/// </summary>
	public class CancelPropertyNotificationEventArgs : PropertyNotificationEventArgs {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the
		/// <see cref="CancelPropertyNotificationEventArgs"/> class.
		/// </summary>
		/// <param name="propertyName">
		/// The name of the property that is associated with this
		/// notification.
		/// </param>
		public CancelPropertyNotificationEventArgs(String propertyName)
			: base(propertyName) {
			// No-op
		}

		/// <summary>
		/// Initializes a new instance of the
		/// <see cref="CancelPropertyNotificationEventArgs"/> class.
		/// </summary>
		/// <param name="propertyName">
		/// The name of the property that is associated with this
		/// notification.
		/// </param>
		/// <param name="oldValue">The old value.</param>
		/// <param name="newValue">The new value.</param>
		public CancelPropertyNotificationEventArgs(String propertyName,
			Object oldValue, Object newValue)
			: base(propertyName, oldValue, newValue) {
			// No-op
		}

		#endregion // Constructors

		#region Properties/Fields

		/// <summary>
		/// Holds a value indicating whether the associated event should be
		/// cancelled.
		/// </summary>
		private Boolean cancel = false;

		/// <summary>
		/// Gets or sets a value indicating whether the associated event should
		/// be cancelled.
		/// </summary>
		/// <value>
		/// <c>true</c> if the event should be cancelled; otherwise, <c>false</c>.
		/// </value>
		public Boolean Cancel {
			get {
				return this.cancel;
			}
			set {
				this.cancel = value;
			}
		}

		#endregion // Properties/Fields
	}
}

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer SQL Farms, Inc.
United States United States
My name is Tom Goff and I have been working as a Software Engineer for over 15 years. Over my career, I have primarily focused on Windows programming with C++ and C#. I have also worked extensively with Microsoft SQL Server over the past 6 years.

Comments and Discussions