本文整理汇总了C#中System.Windows.DependencyProperty.Validate方法的典型用法代码示例。如果您正苦于以下问题:C# DependencyProperty.Validate方法的具体用法?C# DependencyProperty.Validate怎么用?C# DependencyProperty.Validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.DependencyProperty
的用法示例。
在下文中一共展示了DependencyProperty.Validate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetValue
public static void SetValue (INativeDependencyObjectWrapper wrapper, DependencyProperty dp, object value)
{
Type object_type;
if (dp == null)
throw new ArgumentNullException ("property");
CheckNativeAndThread (wrapper);
if (dp.DeclaringType != null && !dp.IsAttached) {
if (!dp.DeclaringType.IsAssignableFrom (wrapper.GetType ()))
throw new System.ArgumentException (string.Format ("The DependencyProperty '{2}', registered on type {0} can't be used to set a value on an object of type {1}", dp.DeclaringType.AssemblyQualifiedName, wrapper.GetType ().AssemblyQualifiedName, dp.Name));
}
if (value == null) {
using (var val = new Value { k = NativeMethods.dependency_property_get_property_type(dp.Native), IsNull = true }) {
var v = val;
NativeMethods.dependency_object_set_value (wrapper.NativeHandle, dp.Native, ref v);
}
return;
}
if (value == DependencyProperty.UnsetValue) {
// Setting to UnsetValue appears to be equivalent to ClearValue
ClearValue (wrapper, dp);
return;
}
// XXX we need this to work with all
// INativeDependencyObjectWrapper, I expect..
// but right now the only one other than DO is
// Application, which doesn't have any
// settable properties, so we're safe for now.
if (wrapper is DependencyObject)
dp.Validate ((DependencyObject)wrapper, dp, value);
object_type = value.GetType ();
bool type_valid = false;
if (dp.PropertyType.IsGenericTypeDefinition) {
Type t = object_type;
while (t != null) {
if (dp.PropertyType.IsAssignableFrom (t)) {
type_valid = true;
break;
}
if (t.IsGenericType && !t.IsGenericTypeDefinition)
t = t.GetGenericTypeDefinition ();
else
t = t.BaseType;
}
}
else {
type_valid = dp.PropertyType.IsAssignableFrom (object_type);
}
if (!type_valid) {
throw new ArgumentException (string.Format ("The DependencyProperty '{3}.{2}', whose property type is {0} can't be set to value whose type is {1}", dp.PropertyType.FullName, object_type.FullName, dp.Name, dp.DeclaringType.FullName));
}
using (var val = Value.FromObject (value, dp is CustomDependencyProperty)) {
var v = val;
NativeMethods.dependency_object_set_value (wrapper.NativeHandle, dp.Native, ref v);
}
}