本文整理汇总了C#中System.Windows.DependencyObject.UpdateEffectiveValue方法的典型用法代码示例。如果您正苦于以下问题:C# DependencyObject.UpdateEffectiveValue方法的具体用法?C# DependencyObject.UpdateEffectiveValue怎么用?C# DependencyObject.UpdateEffectiveValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.DependencyObject
的用法示例。
在下文中一共展示了DependencyObject.UpdateEffectiveValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InvalidateTreeDependentProperty
/// <summary>
/// Invalidate this property if
/// - It is not locally set and
/// - It is not acquired from a style/template
/// </summary>
private static bool InvalidateTreeDependentProperty(
TreeChangeInfo info,
DependencyObject d,
ref FrameworkObject fo,
DependencyProperty dp,
FrameworkPropertyMetadata fMetadata,
Style selfStyle,
Style selfThemeStyle,
ref ChildRecord childRecord,
bool isChildRecordValid,
bool hasStyleChanged,
bool isSelfInheritanceParent)
{
Debug.Assert(d != null, "Must have non-null current node");
// This must be an inherited dependency property
Debug.Assert(fMetadata.IsInherited == true, "This must be an inherited dependency property");
// Children do not need to inherit properties across a tree boundary
// unless the property is set to override this behavior.
if (!SkipNext(fo.InheritanceBehavior) || fMetadata.OverridesInheritanceBehavior)
{
InheritablePropertyChangeInfo rootInfo = info.GetRootInheritableValue(dp);
EffectiveValueEntry oldEntry = rootInfo.OldEntry;
EffectiveValueEntry newEntry = info.IsAddOperation ? rootInfo.NewEntry : new EffectiveValueEntry(dp, BaseValueSourceInternal.Inherited);
bool isForceInheritedProperty = IsForceInheritedProperty(dp);
if (d != info.Root)
{
if (isSelfInheritanceParent)
{
oldEntry = d.GetValueEntry(
d.LookupEntry(dp.GlobalIndex),
dp,
fMetadata,
RequestFlags.DeferredReferences);
}
else
{
oldEntry = oldEntry.GetFlattenedEntry(RequestFlags.FullyResolved);
oldEntry.BaseValueSourceInternal = BaseValueSourceInternal.Inherited;
}
}
OperationType operationType = info.IsAddOperation ? OperationType.AddChild : OperationType.RemoveChild;
if (BaseValueSourceInternal.Inherited >= oldEntry.BaseValueSourceInternal)
{
// If the oldValueSource is of lower precedence than Inheritance
// only then do we need to Invalidate the property. Examples of
// values with higher precedence are those that are locally set
// or set via a style/template.
return (d.UpdateEffectiveValue(
d.LookupEntry(dp.GlobalIndex),
dp,
fMetadata,
oldEntry,
ref newEntry,
false /* coerceWithDeferredReference */,
false /* coerceWithCurrentValue */,
operationType)
& (UpdateResult.ValueChanged | UpdateResult.InheritedValueOverridden))
== UpdateResult.ValueChanged;
// return false if either the value didn't change or
// it changed because the inherited value was overridden by coercion or animation.
}
else if (isForceInheritedProperty)
{
// IsCoerced == true && value == UnsetValue indicates that we need to re-coerce this value
newEntry = new EffectiveValueEntry(dp, FullValueSource.IsCoerced);
// Re-coerce a force inherited property because it's coersion depends on treeness
return (d.UpdateEffectiveValue(
d.LookupEntry(dp.GlobalIndex),
dp,
fMetadata,
oldEntry,
ref newEntry,
false /* coerceWithDeferredReference */,
false /* coerceWithCurrentValue */,
operationType)
& (UpdateResult.ValueChanged | UpdateResult.InheritedValueOverridden))
== UpdateResult.ValueChanged;
// return false if either the value didn't change or
// it changed because the inherited value was overridden by coercion or animation.
}
}
return false;
}
示例2: OnInheritablePropertyChanged
/// <summary>
/// Callback on visiting each node in the descendency
/// during an inheritable property change
/// </summary>
private static bool OnInheritablePropertyChanged(
DependencyObject d,
InheritablePropertyChangeInfo info)
{
Debug.Assert(d != null, "Must have non-null current node");
DependencyProperty dp = info.Property;
EffectiveValueEntry oldEntry = info.OldEntry;
EffectiveValueEntry newEntry = info.NewEntry;
InheritanceBehavior inheritanceBehavior;
bool inheritanceNode = IsInheritanceNode(d, dp, out inheritanceBehavior);
bool isForceInheritedProperty = IsForceInheritedProperty(dp);
// Note that if a node is marked SkipNext means it hasn't acquired any values from its parent and
// hence we do not need to invalidate this node or any of its descendents. However if a node is
// marked SkipNow then this node might have acquired values from its parent but none of its
// descendents would. Hence in this case we process the current node but omit all of its descendents.
if (inheritanceNode && (!SkipNext(inheritanceBehavior) || isForceInheritedProperty))
{
PropertyMetadata metadata = dp.GetMetadata(d);
EntryIndex entryIndex = d.LookupEntry(dp.GlobalIndex);
// Found an inheritance node
if (!d.IsSelfInheritanceParent)
{
DependencyObject parent = FrameworkElement.GetFrameworkParent(d);
InheritanceBehavior parentInheritanceBehavior = InheritanceBehavior.Default;
if (parent != null)
{
FrameworkObject parentFO = new FrameworkObject(parent, true);
parentInheritanceBehavior = parentFO.InheritanceBehavior;
}
if (!SkipNext(inheritanceBehavior) && !SkipNow(parentInheritanceBehavior))
{
// Synchronize InheritanceParent
d.SynchronizeInheritanceParent(parent);
}
// What should the oldValueSource on the child be?
// When the oldValue on the parent was default it
// means that the child also used its own default
// and did not inherit from the parent. However
// when the value on the parent was non-default
// it means that the child inherited it.
// Note that the oldValueSource on inheritablePropertyChangedData
// is actually the parent's oldValueSource
if (oldEntry.BaseValueSourceInternal == BaseValueSourceInternal.Unknown)
{
// we use an empty EffectiveValueEntry as a signal that the old entry was the default value
oldEntry = EffectiveValueEntry.CreateDefaultValueEntry(dp, metadata.GetDefaultValue(d, dp));
}
}
else
{
oldEntry = d.GetValueEntry(
entryIndex,
dp,
metadata,
RequestFlags.RawEntry);
}
// If the oldValueSource is of lower precedence than Inheritance
// only then do we need to Invalidate the property
if (BaseValueSourceInternal.Inherited >= oldEntry.BaseValueSourceInternal)
{
// Since we do not hold a cache of the oldValue we need to supply one
// in order to correctly fire the change notification
return (d.UpdateEffectiveValue(
entryIndex,
dp,
metadata,
oldEntry,
ref newEntry,
false /* coerceWithDeferredReference */,
false /* coerceWithCurrentValue */,
OperationType.Inherit)
& (UpdateResult.ValueChanged | UpdateResult.InheritedValueOverridden))
== UpdateResult.ValueChanged;
// return false if either the value didn't change or
// it changed because the inherited value was overridden by coercion or animation.
}
else if (isForceInheritedProperty)
{
// IsCoerced == true && value == UnsetValue indicates that we need to re-coerce this value
newEntry = new EffectiveValueEntry(dp, FullValueSource.IsCoerced);
// Re-coerce a force inherited property because it's coersion depends on treeness
return (d.UpdateEffectiveValue(
d.LookupEntry(dp.GlobalIndex),
dp,
metadata,
oldEntry,
//.........这里部分代码省略.........
示例3: OnInheritablePropertyChanged
//.........这里部分代码省略.........
entryIndex,
dp,
metadata,
RequestFlags.RawEntry);
}
// If the oldValueSource is of lower precedence than Inheritance
// only then do we need to Invalidate the property
if (BaseValueSourceInternal.Inherited >= oldEntry.BaseValueSourceInternal)
{
if (visitedViaVisualTree && FrameworkElement.DType.IsInstanceOfType(d))
{
DependencyObject logicalParent = LogicalTreeHelper.GetParent(d);
if (logicalParent != null)
{
DependencyObject visualParent = VisualTreeHelper.GetParent(d);
if (visualParent != null && visualParent != logicalParent)
{
// Consider the following logical tree configuration. In this case we want
// to RibbonToggleButton to pick up the new DataContext flowing in from
// the Window.
//
// Window (info.RootElement)
// ...
// RibbonGroup (IsCollapsed)
// RibbonControl (only in visual tree)
// RibbonToggleButton
//
// Consider the following logical tree configuration. In this case we do not
// want to RibbonToggleButton to change its DataContext because the changes
// are only within the visual tree.
//
// Window
// ...
// RibbonGroup (IsCollapsed)
// RibbonControl (only in visual tree) (info.RootElement)
// RibbonToggleButton
//
// Saying it another way, the RibbonToggleButton in the above case belongs in a
// different logical tree than the one that the current invalidation storm begun.
//
// Any change in an inheritable property begins an invalidation storm using the
// DescendentsWalker and configures it to first traverse the logical children
// and then visual children. Also nodes that have previously been visited via the
// logical tree do not get visited again through the visual tree. I use this very
// behavior as the basis for detecting nodes such as RibbonToggleButton. If the
// RibbonToggleButton is being visisted for the first time via the visual tree then
// the invalidation storm did not include its logical parent. And therefore the
// RibbonToggleButton can early out of this storm.
return false;
}
}
}
// Since we do not hold a cache of the oldValue we need to supply one
// in order to correctly fire the change notification
return (d.UpdateEffectiveValue(
entryIndex,
dp,
metadata,
oldEntry,
ref newEntry,
false /* coerceWithDeferredReference */,
false /* coerceWithCurrentValue */,
OperationType.Inherit)
& (UpdateResult.ValueChanged | UpdateResult.InheritedValueOverridden))
== UpdateResult.ValueChanged;
// return false if either the value didn't change or
// it changed because the inherited value was overridden by coercion or animation.
}
else if (isForceInheritedProperty)
{
// IsCoerced == true && value == UnsetValue indicates that we need to re-coerce this value
newEntry = new EffectiveValueEntry(dp, FullValueSource.IsCoerced);
// Re-coerce a force inherited property because it's coersion depends on treeness
return (d.UpdateEffectiveValue(
d.LookupEntry(dp.GlobalIndex),
dp,
metadata,
oldEntry,
ref newEntry,
false /* coerceWithDeferredReference */,
false /* coerceWithCurrentValue */,
OperationType.Inherit)
& (UpdateResult.ValueChanged | UpdateResult.InheritedValueOverridden))
== UpdateResult.ValueChanged;
// return false if either the value didn't change or
// it changed because the inherited value was overridden by coercion or animation.
}
else
{
return false;
}
}
// Do not continue walk down subtree if the walk was forced to stop
// (due to separated trees)
return (inheritanceBehavior == InheritanceBehavior.Default || isForceInheritedProperty);
}