Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DependencyProperty.IsValidType Method (Object)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Determines whether a specified value is acceptable for this dependency property's type, as checked against the property type provided in the original dependency property registration.

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

public bool IsValidType(
	object value
)

Parameters

value
Type: System.Object

The value to check.

Return Value

Type: System.Boolean

true if the specified value is the registered property type or an acceptable derived type; otherwise, false.

A value of null is a valid type for reference type dependency properties, or for a Nullable<T> dependency property, and would return true for these cases. In cases where the dependency property is neither a reference nor a Nullable<T> type, IsValidType will return false for a null value rather than raise an exception.

The following example uses IsValidType as a check before calling SetValue on the dependency property.

void TrySetValue(DependencyObject target, DependencyProperty dp, object providedValue) {
  if (dp.IsValidType(providedValue))
  {
    target.SetValue(dp, providedValue);
  }
}

.NET Framework
Available since 3.0
Return to top
Show:
© 2018 Microsoft