本文整理汇总了C#中System.Windows.PropertyMetadata.GetDefaultValue方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyMetadata.GetDefaultValue方法的具体用法?C# PropertyMetadata.GetDefaultValue怎么用?C# PropertyMetadata.GetDefaultValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.PropertyMetadata
的用法示例。
在下文中一共展示了PropertyMetadata.GetDefaultValue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetValueCommon
//.........这里部分代码省略.........
: null;
// Allow expression to store value if new value is
// not an Expression, if applicable
bool handled = false;
if ((currentExpr != null) && (newExpr == null))
{
// Resolve deferred references because we haven't modified
// the expression code to work with DeferredReference yet.
if (isDeferredReference)
{
value = ((DeferredReference) value).GetValue(BaseValueSourceInternal.Local);
}
// CALLBACK
handled = currentExpr.SetValue(this, dp, value);
entryIndex = CheckEntryIndex(entryIndex, dp.GlobalIndex);
}
// Create the new effective value entry
EffectiveValueEntry newEntry;
if (handled)
{
// If expression handled set, then done
if (entryIndex.Found)
{
newEntry = _effectiveValues[entryIndex.Index];
}
else
{
// the expression.SetValue resulted in this value being removed from the table;
// use the default value.
newEntry = EffectiveValueEntry.CreateDefaultValueEntry(dp, metadata.GetDefaultValue(this, dp));
}
coerceWithCurrentValue = false; // expression already handled the control-value
}
else
{
// allow a control-value to coerce an expression value, when the
// expression didn't handle the value
if (coerceWithCurrentValue && currentExpr != null)
{
currentExpr = null;
}
newEntry = new EffectiveValueEntry(dp, BaseValueSourceInternal.Local);
// detach the old expression, if applicable
if (currentExpr != null)
{
// CALLBACK
DependencySource[] currentSources = currentExpr.GetSources();
UpdateSourceDependentLists(this, dp, currentSources, currentExpr, false); // Remove
// CALLBACK
currentExpr.OnDetach(this, dp);
currentExpr.MarkDetached();
entryIndex = CheckEntryIndex(entryIndex, dp.GlobalIndex);
}
// attach the new expression, if applicable
if (newExpr == null)
{
示例2: GetValueEntry
//.........这里部分代码省略.........
if (metadata == null)
{
metadata = dp.GetMetadata(DependencyObjectType);
}
GetReadOnlyValueCallback getValueCallback = metadata.GetReadOnlyValueCallback;
if (getValueCallback != null)
{
BaseValueSourceInternal valueSource;
entry = new EffectiveValueEntry(dp);
entry.Value = getValueCallback(this, out valueSource);
entry.BaseValueSourceInternal = valueSource;
return entry;
}
}
if (entryIndex.Found)
{
if ((requests & RequestFlags.RawEntry) != 0)
{
entry = _effectiveValues[entryIndex.Index];
}
else
{
entry = GetEffectiveValue(
entryIndex,
dp,
requests);
}
}
else
{
entry = new EffectiveValueEntry(dp, BaseValueSourceInternal.Unknown);
}
if (entry.Value == DependencyProperty.UnsetValue)
{
if (dp.IsPotentiallyInherited)
{
if (metadata == null)
{
metadata = dp.GetMetadata(DependencyObjectType);
}
if (metadata.IsInherited)
{
DependencyObject inheritanceParent = InheritanceParent;
if (inheritanceParent != null)
{
entryIndex = inheritanceParent.LookupEntry(dp.GlobalIndex);
if (entryIndex.Found)
{
entry = inheritanceParent.GetEffectiveValue(
entryIndex,
dp,
requests & RequestFlags.DeferredReferences);
entry.BaseValueSourceInternal = BaseValueSourceInternal.Inherited;
}
}
}
if (entry.Value != DependencyProperty.UnsetValue)
{
return entry;
}
}
if ((requests & RequestFlags.SkipDefault) == 0)
{
if (dp.IsPotentiallyUsingDefaultValueFactory)
{
if (metadata == null)
{
metadata = dp.GetMetadata(DependencyObjectType);
}
if (((requests & (RequestFlags.DeferredReferences | RequestFlags.RawEntry)) != 0) && metadata.UsingDefaultValueFactory)
{
entry.BaseValueSourceInternal = BaseValueSourceInternal.Default;
entry.Value = new DeferredMutableDefaultReference(metadata, this, dp);
return entry;
}
}
else if (!dp.IsDefaultValueChanged)
{
return EffectiveValueEntry.CreateDefaultValueEntry(dp, dp.DefaultMetadata.DefaultValue);
}
if (metadata == null)
{
metadata = dp.GetMetadata(DependencyObjectType);
}
return EffectiveValueEntry.CreateDefaultValueEntry(dp, metadata.GetDefaultValue(this, dp));
}
}
return entry;
}
示例3: EvaluateExpression
private EffectiveValueEntry EvaluateExpression(
EntryIndex entryIndex,
DependencyProperty dp,
Expression expr,
PropertyMetadata metadata,
EffectiveValueEntry oldEntry,
EffectiveValueEntry newEntry)
{
object value = expr.GetValue(this, dp);
bool isDeferredReference = false;
if (value != DependencyProperty.UnsetValue && value != Expression.NoValue)
{
isDeferredReference = (value is DeferredReference);
if (!isDeferredReference && !dp.IsValidValue(value))
{
#region EventTracing
#if VERBOSE_PROPERTY_EVENT
if (isDynamicTracing)
{
if (EventTrace.IsEnabled(EventTrace.Flags.performance, EventTrace.Level.verbose))
{
EventTrace.EventProvider.TraceEvent(EventTrace.PROPERTYGUID,
MS.Utility.EventType.EndEvent,
EventTrace.PROPERTYVALIDATION, 0xFFF );
}
}
#endif
#endregion EventTracing
throw new InvalidOperationException(SR.Get(SRID.InvalidPropertyValue, value, dp.Name));
}
}
else
{
if (value == Expression.NoValue)
{
// The expression wants to "hide". First set the
// expression value to NoValue to indicate "hiding".
newEntry.SetExpressionValue(Expression.NoValue, expr);
// Next, get the expression value some other way.
if (!dp.ReadOnly)
{
EvaluateBaseValueCore(dp, metadata, ref newEntry);
value = newEntry.GetFlattenedEntry(RequestFlags.FullyResolved).Value;
}
else
{
value = DependencyProperty.UnsetValue;
}
}
// if there is still no value, use the default
if (value == DependencyProperty.UnsetValue)
{
value = metadata.GetDefaultValue(this, dp);
}
}
// Set the expr and its evaluated value into
// the _effectiveValues cache
newEntry.SetExpressionValue(value, expr);
return newEntry;
}
示例4: EvaluateEffectiveValue
//.........这里部分代码省略.........
{
newEntry.BaseValueSourceInternal = BaseValueSourceInternal.Unknown;
}
else
{
// if we reached this on a re-evaluate of a setvalue, we need to make sure
// we don't lose track of the newly specified local value.
// for all other cases, the oldEntry will have the local value we should
// use.
value = isSetValue ? newEntry.LocalValue : oldEntry.LocalValue;
if (value == ExpressionInAlternativeStore)
{
value = DependencyProperty.UnsetValue;
}
else
{
oldLocalIsExpression = isSetValue ? newEntry.IsExpression : oldEntry.IsExpression;
}
}
// (If local storage not Unset and not an Expression, return)
if (value != DependencyProperty.UnsetValue)
{
newEntry = new EffectiveValueEntry(dp, BaseValueSourceInternal.Local);
newEntry.Value = value;
// Check if an Expression is set
if (oldLocalIsExpression)
{
// CALLBACK
newEntry = EvaluateExpression(
entryIndex,
dp,
(Expression) value,
metadata,
oldEntry,
newEntry);
entryIndex = CheckEntryIndex(entryIndex, dp.GlobalIndex);
value = newEntry.ModifiedValue.ExpressionValue;
}
}
// Subclasses are not allowed to resolve/modify the value for read-only properties.
if( !dp.ReadOnly )
{
// Give subclasses a chance to resolve/modify the value
EvaluateBaseValueCore(dp, metadata, ref newEntry);
// we need to have the default value in the entry before we do the animation check
if (newEntry.BaseValueSourceInternal == BaseValueSourceInternal.Unknown)
{
newEntry = EffectiveValueEntry.CreateDefaultValueEntry(dp, metadata.GetDefaultValue(this, dp));
}
value = newEntry.GetFlattenedEntry(RequestFlags.FullyResolved).Value;
entryIndex = CheckEntryIndex(entryIndex, dp.GlobalIndex);
if (oldEntry.IsAnimated)
{
newEntry.ResetCoercedValue();
EvaluateAnimatedValueCore(dp, metadata, ref newEntry);
value = newEntry.GetFlattenedEntry(RequestFlags.FullyResolved).Value;
}
}
}
finally
{
#if NESTED_OPERATIONS_CHECK
NestedOperations--;
#endif
}
#region EventTracing
#if VERBOSE_PROPERTY_EVENT
if (isDynamicTracing)
{
if (EventTrace.IsEnabled(EventTrace.Flags.performance, EventTrace.Level.verbose))
{
int UsingDefault = 1;
if (value != DependencyProperty.UnsetValue)
UsingDefault = 0;
EventTrace.EventProvider.TraceEvent(EventTrace.PROPERTYVALIDATIONGUID,
MS.Utility.EventType.EndEvent,
UsingDefault);
}
}
#endif
#endregion EventTracing
if (value == DependencyProperty.UnsetValue)
{
newEntry = EffectiveValueEntry.CreateDefaultValueEntry(dp, metadata.GetDefaultValue(this, dp));
}
return newEntry;
}
示例5: UpdateEffectiveValue
//.........这里部分代码省略.........
if (isReEvaluate ||
(!newEntry.IsAnimated &&
(oldEntry.IsAnimated ||
(oldEntry.IsExpression && newEntry.IsExpression && (newEntry.ModifiedValue.BaseValue == oldEntry.ModifiedValue.BaseValue)))))
{
// we have to compute the new value
if (!isCoerceValue)
{
newEntry = EvaluateEffectiveValue(entryIndex, dp, metadata, oldEntry, newEntry, operationType);
// Make sure that the call out did not cause a change to entryIndex
entryIndex = CheckEntryIndex(entryIndex, targetIndex);
bool found = (newEntry.Value != DependencyProperty.UnsetValue);
if (!found && metadata.IsInherited)
{
DependencyObject inheritanceParent = InheritanceParent;
if (inheritanceParent != null)
{
// Fetch the IsDeferredValue flag from the InheritanceParent
EntryIndex parentEntryIndex = inheritanceParent.LookupEntry(dp.GlobalIndex);
if (parentEntryIndex.Found)
{
found = true;
newEntry = inheritanceParent._effectiveValues[parentEntryIndex.Index].GetFlattenedEntry(RequestFlags.FullyResolved);
newEntry.BaseValueSourceInternal = BaseValueSourceInternal.Inherited;
}
}
}
// interesting that I just had to add this ... suggests that we are now overinvalidating
if (!found)
{
newEntry = EffectiveValueEntry.CreateDefaultValueEntry(dp, metadata.GetDefaultValue(this, dp));
}
}
else
{
if (!oldEntry.HasModifiers)
{
newEntry = oldEntry;
}
else
{
newEntry = new EffectiveValueEntry(dp, oldEntry.BaseValueSourceInternal);
ModifiedValue modifiedValue = oldEntry.ModifiedValue;
object baseValue = modifiedValue.BaseValue;
newEntry.Value = baseValue;
newEntry.HasExpressionMarker = oldEntry.HasExpressionMarker;
if (oldEntry.IsExpression)
{
newEntry.SetExpressionValue(modifiedValue.ExpressionValue, baseValue);
}
if (oldEntry.IsAnimated)
{
newEntry.SetAnimatedValue(modifiedValue.AnimatedValue, baseValue);
}
}
}
}
// Coerce to current value
if (coerceWithCurrentValue)
{