Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

DependencyPropertyChangedEventArgs Structure

Provides data for various property changed events. Typically these events report effective value changes in the value of a read-only dependency property. Another usage is as part of a PropertyChangedCallback implementation.

Namespace:  System.Windows
Assembly:  WindowsBase (in WindowsBase.dll)

'Declaration
Public Structure DependencyPropertyChangedEventArgs

The DependencyPropertyChangedEventArgs type exposes the following members.

  NameDescription
Public methodDependencyPropertyChangedEventArgsInitializes a new instance of the DependencyPropertyChangedEventArgs class.
Top

  NameDescription
Public propertyNewValueGets the value of the property after the change.
Public propertyOldValueGets the value of the property before the change.
Public propertyPropertyGets the identifier for the dependency property where the value change occurred.
Top

  NameDescription
Public methodEquals(DependencyPropertyChangedEventArgs)Determines whether the provided DependencyPropertyChangedEventArgs is equivalent to the current DependencyPropertyChangedEventArgs.
Public methodEquals(Object)Determines whether the provided object is equivalent to the current DependencyPropertyChangedEventArgs. (Overrides ValueType.Equals(Object).)
Public methodGetHashCodeGets a hash code for this DependencyPropertyChangedEventArgs. (Overrides ValueType.GetHashCode.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodToStringReturns the fully qualified type name of this instance. (Inherited from ValueType.)
Top

  NameDescription
Public operatorStatic memberEqualityDetermines whether two specified DependencyPropertyChangedEventArgs objects have the same value.
Public operatorStatic memberInequalityDetermines whether two specified DependencyPropertyChangedEventArgs objects are different.
Top

The events that use the DependencyPropertyChangedEventArgs class for event data, and the DependencyPropertyChangedEventHandler method implementations for handlers, generally follow the naming pattern Is*Changed, and are generally implemented as common language runtime (CLR) events without RoutedEvent backing (they are not routed events). Some class handling methods that "handle" otherwise unexposed events that report a state change through a property change, such as ButtonBase.OnIsPressedChanged, also use the DependencyPropertyChangedEventArgs class for event data.

The scenario for PropertyChangedCallback is to use the arguments to report old and new values that come from the property system evaluation of the property. A callback that processes old and new values might choose special handling depending on these values, such as choosing to not respond to value changes that are deemed insignificant.

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(Of T). The new arguments are then used as the data for a "ValueChanged" event defined by and raised by the custom class.

		Public Shared ReadOnly ValueProperty As DependencyProperty = DependencyProperty.Register("Value", GetType(Decimal), GetType(NumericUpDown), New FrameworkPropertyMetadata(MinValue, New PropertyChangedCallback(AddressOf OnValueChanged), New CoerceValueCallback(AddressOf CoerceValue)))

		Private Shared Overloads Function CoerceValue(ByVal element As DependencyObject, ByVal value As Object) As Object
			Dim newValue As Decimal = CDec(value)

			newValue = Math.Max(MinValue, Math.Min(MaxValue, newValue))

			Return newValue
		End Function

		Private Shared Sub OnValueChanged(ByVal obj As DependencyObject, ByVal args As DependencyPropertyChangedEventArgs)
			Dim control As NumericUpDown = CType(obj, NumericUpDown)

			Dim e As New RoutedPropertyChangedEventArgs(Of Decimal)(CDec(args.OldValue), CDec(args.NewValue), ValueChangedEvent)
			control.OnValueChanged(e)
		End Sub
		''' <summary>
		''' Identifies the ValueChanged routed event.
		''' </summary>
		Public Shared ReadOnly ValueChangedEvent As RoutedEvent = EventManager.RegisterRoutedEvent("ValueChanged", RoutingStrategy.Bubble, GetType(RoutedPropertyChangedEventHandler(Of Decimal)), GetType(NumericUpDown))

		''' <summary>
		''' Occurs when the Value property changes.
		''' </summary>
		Public Custom Event ValueChanged As RoutedPropertyChangedEventHandler(Of Decimal)
			AddHandler(ByVal value As RoutedPropertyChangedEventHandler(Of Decimal))
				MyBase.AddHandler(ValueChangedEvent, value)
			End AddHandler
			RemoveHandler(ByVal value As RoutedPropertyChangedEventHandler(Of Decimal))
				MyBase.RemoveHandler(ValueChangedEvent, value)
			End RemoveHandler
			RaiseEvent(ByVal sender As System.Object, ByVal e As RoutedPropertyChangedEventArgs(Of Decimal))
			End RaiseEvent
		End Event
		''' <summary>
		''' Raises the ValueChanged event.
		''' </summary>
		''' <param name="args">Arguments associated with the ValueChanged event.</param>
		Protected Overridable Sub OnValueChanged(ByVal args As RoutedPropertyChangedEventArgs(Of Decimal))
			MyBase.RaiseEvent(args)
		End Sub

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2015 Microsoft