本文整理汇总了C#中System.Windows.DependencyProperty.IsValidType方法的典型用法代码示例。如果您正苦于以下问题:C# DependencyProperty.IsValidType方法的具体用法?C# DependencyProperty.IsValidType怎么用?C# DependencyProperty.IsValidType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.DependencyProperty
的用法示例。
在下文中一共展示了DependencyProperty.IsValidType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetValue
public void SetValue(DependencyProperty dp, object value)
{
if (IsSealed)
throw new InvalidOperationException ("Cannot manipulate property values on a sealed DependencyObject");
if (!dp.IsValidType (value))
throw new ArgumentException ("value not of the correct type for this DependencyProperty");
ValidateValueCallback validate = dp.ValidateValueCallback;
if (validate != null && !validate(value))
throw new Exception("Value does not validate");
else
properties[dp] = value;
}
示例2: SetValue
/// <summary>
/// Sets the value of a dependency property.
/// </summary>
/// <param name="property">The dependency property whose value is to be set.</param>
/// <param name="value">The value to set.</param>
/// <exception cref="System.ArgumentException">Value is of wrong type for this DependencyProperty.</exception>
public void SetValue(DependencyProperty property, object value)
{
if (!property.IsValidType(value))
throw new ArgumentException("Value is of wrong type for this DependencyProperty.");
if (property.PropertyType.IsValueType)
SetValueType(property, value);
else
SetValueWeakRef(property, value);
}