DependencyPropertyChangedEventArgs.OldValue Property
Gets the value of the property before the change.
Assembly: WindowsBase (in WindowsBase.dll)
The following example uses the DependencyPropertyChangedEventArgs class in the context of a PropertyChangedCallback for a particular property of a custom class that also defines events. The callback takes the results of old and new values from the property system as communicated by DependencyPropertyChangedEventArgs, and repackages these into a different events arguments class RoutedPropertyChangedEventArgs<T>. The new arguments are then used as the data for a "ValueChanged" event defined by and raised by the custom class.
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register( "Value", typeof(decimal), typeof(NumericUpDown), new FrameworkPropertyMetadata(MinValue, new PropertyChangedCallback(OnValueChanged), new CoerceValueCallback(CoerceValue))); private static object CoerceValue(DependencyObject element, object value) { decimal newValue = (decimal)value; newValue = Math.Max(MinValue, Math.Min(MaxValue, newValue)); return newValue; } private static void OnValueChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) { NumericUpDown control = (NumericUpDown)obj; RoutedPropertyChangedEventArgs<decimal> e = new RoutedPropertyChangedEventArgs<decimal>( (decimal)args.OldValue, (decimal)args.NewValue, ValueChangedEvent); control.OnValueChanged(e); } /// <summary> /// Identifies the ValueChanged routed event. /// </summary> public static readonly RoutedEvent ValueChangedEvent = EventManager.RegisterRoutedEvent( "ValueChanged", RoutingStrategy.Bubble, typeof(RoutedPropertyChangedEventHandler<decimal>), typeof(NumericUpDown)); /// <summary> /// Occurs when the Value property changes. /// </summary> public event RoutedPropertyChangedEventHandler<decimal> ValueChanged { add { AddHandler(ValueChangedEvent, value); } remove { RemoveHandler(ValueChangedEvent, value); } } /// <summary> /// Raises the ValueChanged event. /// </summary> /// <param name="args">Arguments associated with the ValueChanged event.</param> protected virtual void OnValueChanged(RoutedPropertyChangedEventArgs<decimal> args) { RaiseEvent(args); }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.