本文整理汇总了C#中System.Windows.DependencyProperty.IsValidValueInternal方法的典型用法代码示例。如果您正苦于以下问题:C# DependencyProperty.IsValidValueInternal方法的具体用法?C# DependencyProperty.IsValidValueInternal怎么用?C# DependencyProperty.IsValidValueInternal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.DependencyProperty
的用法示例。
在下文中一共展示了DependencyProperty.IsValidValueInternal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetValueCommon
/// <summary>
/// The common code shared by all variants of SetValue
/// </summary>
// Takes metadata from caller because most of them have already retrieved it
// for their own purposes, avoiding the duplicate GetMetadata call.
private void SetValueCommon(
DependencyProperty dp,
object value,
PropertyMetadata metadata,
bool coerceWithDeferredReference,
bool coerceWithCurrentValue,
OperationType operationType,
bool isInternal)
{
if (IsSealed)
{
throw new InvalidOperationException(SR.Get(SRID.SetOnReadOnlyObjectNotAllowed, this));
}
Expression newExpr = null;
DependencySource[] newSources = null;
EntryIndex entryIndex = LookupEntry(dp.GlobalIndex);
// Treat Unset as a Clear
if( value == DependencyProperty.UnsetValue )
{
// Parameters should have already been validated, so we call
// into the private method to avoid validating again.
ClearValueCommon(entryIndex, dp, metadata);
return;
}
// Validate the "value" against the DP.
bool isDeferredReference = false;
bool newValueHasExpressionMarker = (value == ExpressionInAlternativeStore);
// First try to validate the value; only after this validation fails should we
// do the more expensive checks (type checks) for the less common scenarios
if (!newValueHasExpressionMarker)
{
bool isValidValue = isInternal ? dp.IsValidValueInternal(value) : dp.IsValidValue(value);
// for properties of type "object", we have to always check for expression & deferredreference
if (!isValidValue || dp.IsObjectType)
{
// 2nd most common is expression
newExpr = value as Expression;
if (newExpr != null)
{
// For Expressions, perform additional validation
// Make sure Expression is "attachable"
if (!newExpr.Attachable)
{
throw new ArgumentException(SR.Get(SRID.SharingNonSharableExpression));
}
// Check dispatchers of all Sources
// CALLBACK
newSources = newExpr.GetSources();
ValidateSources(this, newSources, newExpr);
}
else
{
// and least common is DeferredReference
isDeferredReference = (value is DeferredReference);
if (!isDeferredReference)
{
if (!isValidValue)
{
// it's not a valid value & it's not an expression, so throw
throw new ArgumentException(SR.Get(SRID.InvalidPropertyValue, value, dp.Name));
}
}
}
}
}
// Get old value
EffectiveValueEntry oldEntry;
if (operationType == OperationType.ChangeMutableDefaultValue)
{
oldEntry = new EffectiveValueEntry(dp, BaseValueSourceInternal.Default);
oldEntry.Value = value;
}
else
{
oldEntry = GetValueEntry(entryIndex, dp, metadata, RequestFlags.RawEntry);
}
// if there's an expression in some other store, fetch it now
Expression currentExpr =
(oldEntry.HasExpressionMarker) ? _getExpressionCore(this, dp, metadata)
: (oldEntry.IsExpression) ? (oldEntry.LocalValue as Expression)
: null;
// Allow expression to store value if new value is
// not an Expression, if applicable
bool handled = false;
//.........这里部分代码省略.........