DependencyProperty.IsValidType(Object) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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.
public:
bool IsValidType(System::Object ^ value);
public bool IsValidType (object value);
member this.IsValidType : obj -> bool
Public Function IsValidType (value As Object) As Boolean
Parameters
- value
- Object
The value to check.
Returns
true
if the specified value is the registered property type or an acceptable derived type; otherwise, false
.
Examples
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);
}
}
Private Sub TrySetValue(ByVal target As DependencyObject, ByVal dp As DependencyProperty, ByVal providedValue As Object)
If dp.IsValidType(providedValue) Then
target.SetValue(dp, providedValue)
End If
End Sub
Remarks
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.
Applies to
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기