Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

DependencyObject.InvalidateProperty Method

Re-evaluates the effective value for the specified dependency property

Namespace:  System.Windows
Assembly:  WindowsBase (in WindowsBase.dll)
public void InvalidateProperty(
	DependencyProperty dp
)

Parameters

dp
Type: System.Windows.DependencyProperty
The DependencyProperty identifier of the property to invalidate.

When you call InvalidateProperty, any associated and applicable CoerceValueCallback or PropertyChangedCallback functions registered for that dependency property might be invoked.

Calling InvalidateProperty on a property that has its local value set will have no effect, because the local value takes precedence over other property system inputs, except for animations. However, you could call ClearValue, then call InvalidateProperty. For more information, see Dependency Property Value Precedence.

Calling InvalidateProperty is not necessarily applicable for many dependency property scenarios. If a dependency property becomes invalidated because of value changes in any of the constituents, the property system invalidates and re-evaluates the dependency property automatically. However, there are still some appropriate scenarios where InvalidateProperty is useful. In particular, you can use InvalidateProperty inside the coerce value or property changed callback for a different dependency property. You can also use InvalidateProperty to force re-evaluation of a binding against a data source that is not able to implement the recommended INotifyPropertyChanged notification mechanism (perhaps if consuming data classes that cannot be derived from, or where the data is a static member).

The following example calls InvalidateProperty on a custom property, whenever properties that are involved in the invalidated property's calculations change. This is an alternative technique to calling the CoerceValue method, because invalidating the property will also call any registered CoerceValueCallback.


static AreaButton()
{
    WidthProperty.OverrideMetadata(typeof(AreaButton), new FrameworkPropertyMetadata(new PropertyChangedCallback(InvalidateAreaProperty)));
    HeightProperty.OverrideMetadata(typeof(AreaButton), new FrameworkPropertyMetadata(new PropertyChangedCallback(InvalidateAreaProperty)));
}
static void InvalidateAreaProperty(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    d.InvalidateProperty(AreaProperty);
}


.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

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.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.