本文整理汇总了C#中System.Windows.DependencyObject.SynchronizeInheritanceParent方法的典型用法代码示例。如果您正苦于以下问题:C# DependencyObject.SynchronizeInheritanceParent方法的具体用法?C# DependencyObject.SynchronizeInheritanceParent怎么用?C# DependencyObject.SynchronizeInheritanceParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.DependencyObject
的用法示例。
在下文中一共展示了DependencyObject.SynchronizeInheritanceParent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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,
//.........这里部分代码省略.........
示例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,
bool visitedViaVisualTree)
{
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)
{
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)
//.........这里部分代码省略.........