本文整理汇总了C#中System.Windows.DependencyPropertyKey.SetDependencyProperty方法的典型用法代码示例。如果您正苦于以下问题:C# DependencyPropertyKey.SetDependencyProperty方法的具体用法?C# DependencyPropertyKey.SetDependencyProperty怎么用?C# DependencyPropertyKey.SetDependencyProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.DependencyPropertyKey
的用法示例。
在下文中一共展示了DependencyPropertyKey.SetDependencyProperty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RegisterAttachedReadOnly
/// <summary>
/// Simple registration, metadata, validation, and a read-only property
/// key. Calling this version restricts the property such that it can
/// only be set via the corresponding overload of DependencyObject.SetValue.
/// </summary>
public static DependencyPropertyKey RegisterAttachedReadOnly(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata, ValidateValueCallback validateValueCallback)
{
RegisterParameterValidation(name, propertyType, ownerType);
// Establish default metadata for all types, if none is provided
if (defaultMetadata == null)
{
defaultMetadata = AutoGeneratePropertyMetadata( propertyType, validateValueCallback, name, ownerType );
}
// We create a DependencyPropertyKey at this point with a null property
// and set that in the _readOnlyKey field. This is so the property is
// marked as requiring a key immediately. If something fails in the
// initialization path, the property is still marked as needing a key.
// This is better than the alternative of creating and setting the key
// later, because if that code fails the read-only property would not
// be marked read-only. The intent of this mildly convoluted code
// is so we fail securely.
DependencyPropertyKey authorizedKey = new DependencyPropertyKey(null);
DependencyProperty property = RegisterCommon( name, propertyType, ownerType, defaultMetadata, validateValueCallback);
property._readOnlyKey = authorizedKey;
authorizedKey.SetDependencyProperty(property);
return authorizedKey;
}
示例2: RegisterReadOnly
/// <summary>
/// Simple registration, metadata, validation, and a read-only property
/// key. Calling this version restricts the property such that it can
/// only be set via the corresponding overload of DependencyObject.SetValue.
/// </summary>
public static DependencyPropertyKey RegisterReadOnly(
string name,
Type propertyType,
Type ownerType,
PropertyMetadata typeMetadata,
ValidateValueCallback validateValueCallback )
{
RegisterParameterValidation(name, propertyType, ownerType);
PropertyMetadata defaultMetadata = null;
if (typeMetadata != null && typeMetadata.DefaultValueWasSet())
{
defaultMetadata = new PropertyMetadata(typeMetadata.DefaultValue);
}
else
{
defaultMetadata = AutoGeneratePropertyMetadata(propertyType,validateValueCallback,name,ownerType);
}
// We create a DependencyPropertyKey at this point with a null property
// and set that in the _readOnlyKey field. This is so the property is
// marked as requiring a key immediately. If something fails in the
// initialization path, the property is still marked as needing a key.
// This is better than the alternative of creating and setting the key
// later, because if that code fails the read-only property would not
// be marked read-only. The intent of this mildly convoluted code
// is so we fail securely.
DependencyPropertyKey authorizationKey = new DependencyPropertyKey(null); // No property yet, use null as placeholder.
DependencyProperty property = RegisterCommon(name, propertyType, ownerType, defaultMetadata, validateValueCallback);
property._readOnlyKey = authorizationKey;
authorizationKey.SetDependencyProperty(property);
if (typeMetadata == null )
{
// No metadata specified, generate one so we can specify the authorized key.
typeMetadata = AutoGeneratePropertyMetadata(propertyType,validateValueCallback,name,ownerType);
}
// Authorize registering type for read-only access, create key.
#pragma warning suppress 6506 // typeMetadata is never null, since we generate default metadata if none is provided.
// Apply type-specific metadata to owner type only
property.OverrideMetadata(ownerType, typeMetadata, authorizationKey);
return authorizationKey;
}