Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6681091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:33:03+00:00 2026-05-26T04:33:03+00:00

Is there an INotifyPropertyChanged-like interface where the event args contains the old value of

  • 0

Is there an INotifyPropertyChanged-like interface where the event args contains the old value of the property being changed, or do I have to extend that interface to create one?

For example:

    public String ProcessDescription
    {
        get { return _ProcessDescription; }
        set
        {
            if( value != ProcessDescription )
            {
                String oldValue = _ProcessDescription;
                _ProcessDescription = value;
                InvokePropertyChanged("ProcessDescription", oldvalue);
            }
        }
    }

    InvokePropertyChanged(String PropertyName, OldValue)
    {
         this.PropertyChanged( new ExtendedPropertyChangedEventArgs(PropertyName, OldValue) );
    }

I would also settle for a PropertyChanging-like event which provides this information, whether or not it supports e.Cancel.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:33:03+00:00Added an answer on May 26, 2026 at 4:33 am

    As indicated by the answers, I had to implement my own solution. For the benefit of others, I’ve presented it here:

    The Extended PropertyChanged Event

    This event has been specially designed to be backwards compatible with old propertyChanged events. It can be used interchangeably with the simple PropertyChangedEventArgs by callers. Of course, in such cases, it is the responsibility of the event handler to check if the passed PropertyChangedEventArgs can be downcast to a PropertyChangedExtendedEventArgs, if they want to use it. No downcasting is necessary if all they’re interested in is the PropertyName property.

    public class PropertyChangedExtendedEventArgs<T> : PropertyChangedEventArgs
    {
        public virtual T OldValue { get; private set; }
        public virtual T NewValue { get; private set; }
    
        public PropertyChangedExtendedEventArgs(string propertyName, T oldValue, T newValue)
            : base(propertyName)
        {
            OldValue = oldValue;
            NewValue = newValue;
        }
    }
    

    Example 1

    The user can now specify a more advanced NotifyPropertyChanged method that allows property setters to pass in their old value:

    public String testString
    {
        get { return testString; }
        set
        {
            String temp = testString;
            testValue2 = value;
            NotifyPropertyChanged("TestString", temp, value);
        }
    }
    

    Where your new NotifyPropertyChanged method looks like this:

    protected void NotifyPropertyChanged<T>(string propertyName, T oldvalue, T newvalue)
    {
        OnPropertyChanged(this, new PropertyChangedExtendedEventArgs<T>(propertyName, oldvalue, newvalue));
    }
    

    And OnPropertyChanged is the same as always:

    public virtual void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
            handler(sender, e);
    }
    

    Example 2

    Or if you prefer to use lambda expressions and do away with hard-coded property name strings entirely, you can use the following:

    public String TestString
    {
        get { return testString; }
        private set { SetNotifyingProperty(() => TestString, ref testString, value); }
    }
    

    Which is supported by the following magic:

    protected void SetNotifyingProperty<T>(Expression<Func<T>> expression, ref T field, T value)
    {
        if (field == null || !field.Equals(value))
        {
            T oldValue = field;
            field = value;
            OnPropertyChanged(this, new PropertyChangedExtendedEventArgs<T>(GetPropertyName(expression), oldValue, value));
        }
    }
    protected string GetPropertyName<T>(Expression<Func<T>> expression)
    {
        MemberExpression memberExpression = (MemberExpression)expression.Body;
        return memberExpression.Member.Name;
    }
    

    Performance

    If performance is a concern, see this question: Implementing NotifyPropertyChanged without magic strings.

    In summary, the overhead is minimal. Adding the old value and switching to the extended event is about a 15% slowdown, still allowing for on the order of one million property notifications per second, and switching to lambda expressions is a 5 times slowdown allowing for approximately one hundred thousand property notifications per second. These figures are far from being able to form a bottleneck in any UI-driven application.


    (Optional) The Extended PropertyChanged Interface

    Note: You do not have to do this. You can still just implement the standard INotifyPropertyChanged interface.

    If the programmer wants to create an event that requires notifying properties to include an old value and a new value, they would need to define and implement the following interface:

    // Summary: Notifies clients that a property value is changing, but includes extended event infomation
    /* The following NotifyPropertyChanged Interface is employed when you wish to enforce the inclusion of old and
     * new values. (Users must provide PropertyChangedExtendedEventArgs, PropertyChangedEventArgs are disallowed.) */
    public interface INotifyPropertyChangedExtended<T>
    {
        event PropertyChangedExtendedEventHandler<T> PropertyChanged;
    }
    
    public delegate void PropertyChangedExtendedEventHandler<T>(object sender, PropertyChangedExtendedEventArgs<T> e);
    

    Now anyone hooking the PropertyChanged event needs to supply the extended args defined above. Note that depending on your use case, your UI may still require you to implement the basic INotifyPropertyChanged interface and event, which would conflict with this one. This is the sort of thing you would do if, for instance, you were building your own UI elements that hinged on this behaviour.


    8 Years Later FAQ – How do I use it?

    The above examples show how you would send the new property information, but not how you would consume them. 8 Years late, but here’s an example of an implementation of the event (shout-out to @Paddy for filling in for the deficiency the past 6 years):

    myNotifyingClass.PropertyChanged += OnSomePropertyChanged;
    
    private void OnSomePropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        // Without casting 'e' is a standard PropertyChanged event
        Debug.WriteLine($"'{e.PropertyName}' has changed.");
    
        // If you just care to check whether a certain properties changed, do so as usual
        if (e.PropertyName == nameof(SomeClass.Description))
        {
            myNotifyingClass.MarkAsDirty(); // For example
        }
    
        // If the old/new value are if interest, you can cast in those situations
        if (e.PropertyName == nameof(SomeClass.SortKey))
        {
            // For example, use it to order by some new property first, but by the last property second.
            if(e is PropertyChangedExtendedEventArgs<string> sortKeyChanged)
                myNotifyingClass.OrderBy(sortKeyChanged.NewValue, then_by: sortKeyChanged.OldValue);
            else
                throw new Exception("I must have forgotten to use the extended args!");
        }
    
        // To support more general operations, see the note below on creating interfaces
    }
    

    As we note in the above example, there’s not much we can do with these generic arguments without casting first. That’s because 8 years ago, I may or may not have even known what covariance was. If you would like this to be even more useful, it may make sense to define some interfaces you can use to do type checking and extract property values without knowing the runtime type:

    public interface IPropertyChangedExtendedEventArgs<out T> : IPropertyChangedEventArgs
    {
        public virtual T OldValue { get; }
        public virtual T NewValue { get; }
    }
    
    public class PropertyChangedExtendedEventArgs<T> : IPropertyChangedExtendedEventArgs<T>
    {
        public virtual T OldValue { get; private set; }
        public virtual T NewValue { get; private set; }
    
        public PropertyChangedExtendedEventArgs(string propertyName, T oldValue, T newValue)
            : base(propertyName)
        {
            OldValue = oldValue;
            NewValue = newValue;
        }
    }
    

    This is now much nicer to use:

    if (e is IPropertyChangedExtendedEventArgs<object> anyProperty)
        Console.WriteLine($"'{anyProperty.PropertyName}' has changed, " + 
            $"from '{anyProperty.OldValue}' to '{anyProperty.NewValue}'.");
    

    I hope that clears things up!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some nested view models that implement INotifyPropertyChanged . I'd like to bind
I have a custom object that implements INotifyPropertyChanged. I have a collection of these
I have a INotifyPropertyChanged derived class with a Volume property (float, 0.0f - 1.0f)
If I have a dbml file that contains say a Customer class with say
I have a ViewModel that encapsulates some properties that are being edited in an
Picture this DTO-like class: class LineItem : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public
I've got a WPF app that's using INotifyPropertyChanged to signal property updates. What I
I feel like this should be very possible. I have an interface, let's call
There is a conversion process that is needed when migrating Visual Studio 2005 web
There are a few ways to get class-like behavior in javascript, the most common

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.