DependencyProperty.IsValidValue Method

Determines whether the provided value is accepted for the type of property, and also if it is within the allowed range of values for that type, as specified by any ValidateValueCallback provided in the dependency property registration.

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

public bool IsValidValue (
	Object value
)
public boolean IsValidValue (
	Object value
)
public function IsValidValue (
	value : Object
) : boolean
You cannot use methods in XAML.

Parameters

value

The value to check.

Return Value

true if the value is acceptable and is of the correct type or a derived type; otherwise, false.

This method calls IsValidType internally. If the dependency property in question has no ValidateValueCallback,then calling this method is effectively equivalent to calling IsValidType. If the dependency property does have a ValidateValueCallback, and if IsValidType would have returned true, then the value returned will be as implemented in the callback.

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

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

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

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show: