DependencyObject.InvalidateProperty(DependencyProperty) DependencyObject.InvalidateProperty(DependencyProperty) DependencyObject.InvalidateProperty(DependencyProperty) DependencyObject.InvalidateProperty(DependencyProperty) Method

定義

重新評估指定之相依性屬性的有效值。Re-evaluates the effective value for the specified dependency property

public:
 void InvalidateProperty(System::Windows::DependencyProperty ^ dp);
public void InvalidateProperty (System.Windows.DependencyProperty dp);
member this.InvalidateProperty : System.Windows.DependencyProperty -> unit
Public Sub InvalidateProperty (dp As DependencyProperty)

參數

dp
DependencyProperty DependencyProperty DependencyProperty DependencyProperty

要使其失效之屬性的 DependencyProperty 識別項。The DependencyProperty identifier of the property to invalidate.

範例

下列範例會呼叫InvalidateProperty自訂屬性,只要涉及失效之屬性的計算中的屬性變更。The following example calls InvalidateProperty on a custom property, whenever properties that are involved in the invalidated property's calculations change. 這是一個替代的方法來呼叫CoerceValue方法,因為失效屬性也稱之為任何註冊CoerceValueCallbackThis 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);
}
Shared Sub New()
	WidthProperty.OverrideMetadata(GetType(AreaButton), New FrameworkPropertyMetadata(New PropertyChangedCallback(AddressOf InvalidateAreaProperty)))
	HeightProperty.OverrideMetadata(GetType(AreaButton), New FrameworkPropertyMetadata(New PropertyChangedCallback(AddressOf InvalidateAreaProperty)))
End Sub
Private Shared Sub InvalidateAreaProperty(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
	d.InvalidateProperty(AreaProperty)
End Sub

備註

當您呼叫InvalidateProperty、 任何相關和適用CoerceValueCallbackPropertyChangedCallback函式註冊該相依性屬性可能會叫用。When you call InvalidateProperty, any associated and applicable CoerceValueCallback or PropertyChangedCallback functions registered for that dependency property might be invoked.

呼叫InvalidateProperty設定其本機值在屬性上會有任何作用,因為本機的值會優先於其他屬性系統輸入,除了動畫。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. 不過,您可以呼叫ClearValue,然後呼叫InvalidatePropertyHowever, you could call ClearValue, then call InvalidateProperty. 如需詳細資訊,請參閱相依性屬性值優先順序For more information, see Dependency Property Value Precedence.

呼叫InvalidateProperty不一定適用於許多相依性屬性案例。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. 不過,仍有某些適當的情況下,InvalidateProperty很有用。However, there are still some appropriate scenarios where InvalidateProperty is useful. 特別是,您可以使用InvalidateProperty內屬性的強制轉型值變更為不同的相依性屬性回呼。In particular, you can use InvalidateProperty inside the coerce value or property changed callback for a different dependency property. 您也可以使用InvalidateProperty強制對無法實作建議的資料來源繫結的重新評估INotifyPropertyChanged通知機制 (或許是否有使用,不能衍生自,或其中的資料是靜態的資料類別成員)。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).

適用於

另請參閱