NewValue Property
Collapse the table of content
Expand the table of content

DependencyPropertyChangedEventArgs.NewValue Property

 

Gets the value of the property after the change.

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

Public ReadOnly Property NewValue As Object

Property Value

Type: System.Object

The property value after the change.

The type of the value provided should always be castable to the type of the dependency property being reported.

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
Available since 3.0
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top
Show:
© 2016 Microsoft